Ethers.js vs Web3.js SDK Comparison

Learn about the similarities and differences between the two most popular Ethereum Javascript libraries.

Virtually every web3 website, or dapp that you have ever used uses one of web3.js or ethers.js. Together, they are the two most popular Ethereum JavaScript libraries that allow developers to interact with Ethereum or EVM-compatible blockchains using the JSON-RPC (JavaScript Object Notation- Remote Procedure Call) protocol.

In other words, these are JavaScript libraries that allow you to do things that fundamental to almost every dapp: deploy smart contracts, create wallets, sign transactions, query the blockchain, etc. without having to make raw API calls to the blockchain.

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.

What is ethers.js?

According to its developers, ethers.js is a complete Ethereum wallet implementation and utilities in JavaScript and TypeScript. It is an extremely popular library that allows you to interact with Ethereum and EVM-compatible blockchains, and read and modify its state.

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:

  1. A wallet that is capable of signing transactions with a private key
  2. 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!

If you're using Ethers.js but you also want access to certain Alchemy-specific features such as our NFT API, Enhanced WebSockets, Transact features, or Token API, read on!

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.

Alchemy SDK Quickstart

Advantages of ethers.js

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:

A Broader License

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.

Smaller Size

Ethers is an extremely lightweight library. It's only 77 KB compressed and 284 KB uncompressed.

ENS Compatible

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.

A large number of test cases

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).

Drawbacks of ethers.js

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.

When to use ethers.js

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.


What is web3.js?

Web3.js is the original Ethereum JavaScript API library created by the Ethereum Foundation (it has since outsourced active development to a company named ChainSafe).

Launched in 2015, web3.js continues to be the most popular Ethereum library (written in JavaScript or otherwise) and is a part of more projects and packages than any other library of its kind.

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.

Advantages of web3.js

Backed by the Ethereum Foundation

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.

Extremely Popular

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.

Drawbacks of web3.js

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.

When to use web3.js

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.

Head-to-Head Comparison

Popularity

Web3 is currently the most popular Ethereum JavaScript library in the world. However, Ethers is currently experiencing a larger growth in popularity.

LibraryGitHub StarsGitHub ForksNPM Weekly DownloadsIssuesPull Requests
Web3.js 16.4k4.3k618k15120
Ethers.js 5.9k1.3k1M26367

Performance

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.

Maintenance

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.

Usability

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.

Documentation

Both libraries have extensive documentation. However, ethers has a slight edge on account of its extensive and beginner-friendly Getting Started guide and its playground.

Features

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.

Notify API Quickstart
Alchemy SDK Quickstart
Transfers API Quickstart

📘

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!

Developer Experience

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 Support

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.

Conclusion

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!


ReadMe