Metamask

如何查看 MetaMask 是否安裝?

  • February 28, 2022

如何從客戶端 JavaScript 檢查是否安裝了 MetaMask?

if (typeof window.ethereum !== 'undefined') {
 console.log('MetaMask is installed!');
}

元遮罩文件

不是特別是 Metamask,但下面檢查是否正在註入 Web3。

window.addEventListener('load', function() {

 // Check if Web3 has been injected by the browser (Mist/MetaMask).
 if (typeof web3 !== 'undefined') {
   // Use Mist/MetaMask's provider.
   web3js = new Web3(web3.currentProvider);
 } else {
   // Handle the case where the user doesn't have web3. Probably 
   // show them a message telling them to install Metamask in 
   // order to use the app.
 }

});

引用自:https://ethereum.stackexchange.com/questions/44601