|Date of first release||Feb 2015||Jul 2016|
*GitHub contributors from March 1, 2021 to March 1, 2022
**16 contributors, but only 2 had more than 10 commits in the one year period
***Bundle size from bundlephobia, value of minified and gzipped package.
While web3.js provides a single instantiated web3 object with methods for interacting with the blockchain, ethers.js separates the API into two separate roles. The
provider, which is an anonymous connection to the ethereum network, and the
signer, which can access the private key and sign the transactions. The ethers team intended this separation of concerns to provide more flexibility to developers.
Below are some examples of common functions a developer would include in their dapp. You'll see they offer the same functionality, with some slight differences of API.
const web3 = new Web3(Web3.givenProvider);
const provider = new ethers.providers.Web3Provider(window.ethereum)
const balance = await web3.eth.getBalance("0x0")
ethers (supports ENS!)
const balance = await provider.getBalance("ethers.eth")
const myContract = new web3.eth.Contract(ABI, contractAddress);
const myContract = new ethers.Contract(contractAddress, ABI, provider.getSigner());
const balance = await myContract.methods.balanceOf("0x0").call()
const balance = await myContract.balanceOf("ethers.eth")
Given the details above, web3.js looks like the go-to choice, with a longer history and more maintainers. However, ethers.js seems just as reliable and includes some differentiating perks such as size and additional features. Most other articles on this subject conclude that you could easily pick either, depending on what you're looking for.
I too hesitate to recommend one over the other. But as the ecosystem evolves, it is important to me to pick the library that will be most flexible and supported by other libraries.
As the dapp ecosystem grows, which of the two libraries will be the most compatible with other open source libraries you want to bring into your app?
In my limited experience, as this is still an emerging area for development, there are a couple libraries that require ethers.js to use the framework. Examples include web3-react and NFT Swap SDK. I have not yet seen libraries that require web3.js.
Implementing end-to-end testing for web3 features is a challenge. This is partly because most tools, like Cypress, run your tests in a Chromium browser that does not support browser extensions. Developers need an easy way to mock Ethereum providers or the web3/ethers instance to use inside their test environments. So far, I haven't seen any libraries that help solve this. But if there were a tool that helped mock providers for testing, and only worked with ethers for example, that would be enough for me to choose ethers over web3.
Which library do you prefer, web3.js or ethers.js? Are there any tools in the ecosystem I'm overlooking? Let me know in the comments!