Can anyone write a short comparison between the most important features of the two libraries?
For me, it is less about features (however there are a couple cool features/design choices in ethers.js).
- well tested
- well documented
- well maintained
- less buggy
If you want to use ethers, you might want to check Waffle, a framework for creating smart contracts with ethers.
web3.js vs. ethers.js
One major difference between ethers.js and web3 is how they handle key management and interaction with the ethereum blockchain. Web3 assumes that there is a local node connected to the application. That node is assumed to store keys, sign transactions, and interact with and read the ethereum blockchain. In reality, this is not often the case — most users are not running geth locally. Metamask effectively emulates that environment through a browser application, and so most web3 apps require Metamask to hold keys, sign transactions, and interact with the ethereum mainnet.
Ethers.js takes a different approach that we believe gives developers more flexibility. Ethers.js separates the “node” into two separate roles:
A “wallet” that holds keys and signs transaction, and
A “provider” that serves as an anonymous connection to the ethereum network, checking state and sending transactions
The 2 main advantages of ethers.js in my mind are:
- ENS names are first-class citizens
- key management and state - separation of concerns
There are a number of other differentiating factors.
Why I prefer ethers.js over web3.js
- List item
- less buggy
- Huge size difference. Web3 is very bulky for a frontend use
- concise documentation
- Easier for beginners
- New Projects are using ethers.js over web3
For web3, well it is a mist standard.
You'll get a good idea using the sample apps here: https://github.com/adrianmcli/web3-vs-ethers
On top of all the good answers written here, I'd like to add Adrian Li's recently published comparison of web3 vs ethers.js:
It's a GitHub repo with a comprehensible README and code examples.
Ether.js is developed and maintained by Rick Moore – A canadian developer.
Web3.js is a developed and maintained by Ethereum Foundation. So, there is a wider support for Web3.js as more number of developers are behind it.
Ethers.js has 4k github starts on Feb 2, 2022. Web3.js is older library. So it is more popular. It has 13.4k github stars on Feb 2, 2022.
Ethers.js offers full type-script support. Web3.js started typescript support after v1.3.0
Advantages of Ethers.js over Web3.js
- Ethers.js has pre-written tests with proper documentation. So,it is better for testing smart contracts. Ether.js is only 77kb compressed. So it is very light.
- ENS name can be used in place of contract address.
- Separate handling of key-management and state(provider) which increases security.