Skip to content Skip to sidebar Skip to footer

Web3 and ethers are JavaScript libraries that allow front-end apps to communicate with the Ethereum blockchain. If you’re developing an app that reads or writes to the blockchain from the client you need to use one of these libraries. How they’ll be maintained and grown in the dApp ecosystem is a critical question.

web3.js and ether.js Comparison

GitHub Stars13.4k4k
Bundle size590kb116kb

web3.js and ether.js API Comparison

Whereas the web3.js API creates a single web3 object with methods to interact with the blockchain, ethers.js divides the API into two distinct roles. Transactions can be signed by both the provider and the signer, both of whom can access the private key. The goal of this separation of concerns was to give developers more freedom.

The following is a list of some of the most common dApp functions. While they have similar features, there are some subtle differences in the API that you should be aware of.

Instantiating provider with MetaMask wallet

const web3 = new Web3(Web3.givenProvider);

const provider = new ethers.providers.Web3Provider(window.ethereum)

Getting balance of account

const balance = await web3.eth.getBalance("0x0")

ethers (supports ENS!)
const balance = await provider.getBalance("ethers.eth")

Instantiating contract

const myContract = new web3.eth.Contract(ABI, contractAddress);

const myContract = new ethers.Contract(contractAddress, ABI, provider.getSigner());

Calling contract method

const balance = await myContract.methods.balanceOf("0x0").call()

const balance = await myContract.balanceOf("ethers.eth")

Which one should I choose?

Web3.js appears to be the best option based on the information presented above, as it has a longer history and a larger community of maintainers. Aside from the fact that it is more compact and has a few extra features, it appears to be equally reliable. According to the majority of other articles on this topic, you can choose either one depending on your needs.

Leave a comment

> Newsletter <
Interested in Tech News and more?