[Ethereum] Using ether.js with metamask

metamaskweb3js

I am considering using ether.js instead of web3js. One of the factors I am considering is the integration with metamask.

Is there any support in ether.js to use metamask as wallet?
If there isn't, will a simple decorator pattern wrapping around browserside-metamask-injected-web3js do the trick?

One more question, is ether.js stable and well supported?

Best Answer

Actually the answer can be found in the ethers.js doc.

Ethers.js supports web3 providers, so to get it to work metamask on browser is quite simple.

if (typeof web3 !== 'undefined') {
  var web3Provider = new ethers.providers.Web3Provider(web3.currentProvider, ethers.providers.networks.ropsten);
  web3Provider.getBalance("..some address.."). then(function(balance) {
    var etherString = ethers.utils.formatEther(balance);
    console.log("Balance: " + etherString);
  });
}
Related Topic