One of the most common questions developers ask when starting out with web3 development is which library to use in their projects. In this guide, we will cover what ethers.js and web3.js libraries are, what they can do, and how they differ so you're able to make a choice depending on the requirements of your project.
Ethers.js was launched in 2015 by a Canadian software engineer named Richard Moore (or RicMoo) as a powerful, lightweight alternative to Web3.js.
Since its inception, ethers has experienced a meteoric rise in popularity amongst Ethereum and EVM developers. It is not uncommon for projects and companies launched post 2017 to use it on a first preference basis.
A key differentiator of ethers is how it handles key management and interaction with the blockchain. In ethers, there are two separate entities handling the above:
- A wallet that is capable of signing transactions with a private key
- A provider that connects to the blockchain network (usually using a JSON-RPC URL), checks state, and sends transactions.
Separating the wallet and the provider allows developers to handle them separately. For instance, you can use Alchemy as a provider and Metamask as a wallet if you're leveraging ethers on your dapp.
The Alchemy SDK is a superset of Ethers.js!
We built a strict superset of Ethers.js that makes it simple to integrate your Ethers.js code into Alchemy's custom endpoints, called the Alchemy SDK. You'll get the same syntax and features as Ethers while gaining access to Alchemy's best-in-class infrastructure and Enhanced APIs.
Ethers can do everything that web3.js can when it comes to interacting with the blockchain. In addition to that, it has a few more perks:
Ethers is available under the MIT License which not only allows developers to use it for free, but also allows modifications to it.
The latter is also allowed under the LGPL-3.0 license that web3 uses but it also forces you to release the source code containing the modifications.
Ethers is an extremely lightweight library. It's only 77 KB compressed and 284 KB uncompressed.
Ethers knows how to parse ENS domain names by default. Therefore, you can replace a hexadecimal address with a .eth domain without any extra boilerplate code.
Ethers is extraordinarily well-tested, with close to 10,000 test cases; a significant chunk being written by Richard Moore himself. Ethers was a pioneer with respect to maintaining a well-tested Ethereum library (web3 has since managed to catch up to an extent).
Ethers is a relatively new library. Hence, it is hard to find it in use in older, more foundational projects and companies. If you work or are planning to work in such a company, it may be worthwhile to spend more time learning web3.
Ethers is a fantastic library to use if you're building a new project. At the time of writing, the popularity (in terms of weekly downloads, beginner tutorials, and community support) has either surpassed or quickly catching up to that of web3.
Given the small size of the library, it is especially lucrative on the frontend as it can improve the performance of your website/app significantly.
Unlike Ethers, web3 does not separate wallets and providers. Instead, it assumes that there is a local node connected to the application that is single-handedly capable of storing keys, signing transactions, and reading state from the blockchain network it is connected to.
As stated earlier, web3.js was created by the Ethereum Foundation, possibly the single most important entity in the Ethereum and EVM ecosystem. This makes the library extremely robust and future-proof.
Having a large number of contributors also ensures that web3 innovates quickly and rectifies its weaknesses. For instance, when ethers was launched in 2017, testing capabilities of web3 was extremely poor. It has since managed to catch up.
Prior to 2017, web3 was the only viable Ethereum JS library available. As a result, a lot of the foundational projects still continue to use web3.
In terms of absolute popularity, web3 is still at the top. It is relatively easier to find tutorials, developers, community support, and internet forum Q&A pertaining to web3 as compared to its alternatives.
Web3.js has fallen out of favor with relatively newer projects. There seems to be a preference to using ethers with projects and companies founded after 2017.
Web3 also operates under a more restrictive license that doesn't allow modification of its source code unless the modification is released publicly.
Finally, web3 is significantly larger than ethers. Using it in a frontend can lead to a reduction in performance and speed of the website.
Web3.js is a fantastic option (and sometimes the only option) when working with relatively older and more mature stacks, projects, and companies.
It is also a great tool to start working with if you're a beginner, given the volume of tutorials and support available that leverages the library.
|Library||GitHub Stars||GitHub Forks||NPM Weekly Downloads||Issues||Pull Requests|
Ethers is a more lightweight and performant library as compared to web3. It is only 77 KB compressed and 284 KB uncompressed. On the other hand, the respective sizes for web3 are of the order of a few megabytes.
Web3 has the direct support of the Ethereum Foundation, and is being actively maintained by Chainsafe. It has 304 contributors listed on GitHub and 4 collaborators listed on NPM.
Ethers, on the other hand, is maintained by an independent software engineer. It lists 15 contributors on GitHub and 1 collaborator on NPM.
Web3 bundles wallets and providers into a single object whereas ethers treats them discretely and separately. As a result, it is possible to divorce reading and modifying blockchain state from signing and maintaining keys using ethers.
Both libraries support all standard functionality expected of an Ethereum API (connecting to a node, signing transactions, creating wallets, deploying contracts, etc.)
Ethers has a few nice-to-have features over and above the functionalities listed above such as automatic ENS parsing.
Alchemy SDK vs. Ethers.js
As a superset of Ethers, Alchemy SDK supports all commonly used features of Ethers.js.
However, if you're looking for support for the following Alchemy-specific features, we'd recommend you check out the Alchemy SDK that provides support for these APIs in an Ethers-friendly package!
Both libraries make it possible achieve powerful things on the blockchain using extremely few lines of code.
However, ethers code is usually perceived to be cleaner on account of its separation of concerns (w.r.t wallets and providers).
On the other hand, beginners might find it easier to discover tutorials, projects, and support documents written in web3. Some of the most popular web3 learning resources (such as Cryptozombies) use the web3 library.
Alchemy provides extensive support for both libraries. As such, you can interact with Alchemy nodes using either library.
However, if you'd like to use Ethers.js functionality, we'd recommend you use the Alchemy SDK instead - a NPM package that is a strict superset of Ethers functionality with identical syntax, but adds support for a variety of Alchemy's Enhanced APIs such as our NFT API, Enhanced WebSockets, Transact features, and Token API.
Congratulations! You now know the basic differences between ethers and web3, and when a particular library is a good choice.
If you enjoyed this article, or have feedback, tweet us at @AlchemyPlatform!
Don't forget to join our Discord server to meet other blockchain devs, builders, and entrepreneurs!
Ready to start using Alchemy?
Create a free Alchemy account and do share your project with us!
Updated 17 days ago