Search
Generic filters
Share on facebook
Share on twitter
Share on linkedin

Web3.js vs Ethers.js – Guide to ETH JavaScript Libraries

These days, crypto developers can choose among multiple programmable blockchains to build on. And, while you can hear the term “Ethereum killers” being thrown around quite often, the first mover remains the king. As such, the majority of blockchain developers still focus on Ethereum. Moreover, since other programmable chains tend to follow Ethereum’s lead, most of them are EVM-compatible. Thus, the same JavaScript libraries can be used to deploy dApps (decentralized applications) across multiple chains. With that in mind, you ought to take a closer look at Web3.js vs Ethers.js comparison. 

Herein, you will get a chance to learn what Web3.js and Ethers.js are. You’ll also learn about JavaScript modules. Moreover, we’ll take a quick overview of the modules of each of the two JavaScript ETH libraries. However, the core of this article is the Web3.js vs Ethers.js comparison. It will help you establish a clear picture of the benefits and disadvantages of each library. Moreover, it should also make things clearer why the majority of the crypto industry is moving towards the younger of the two libraries. With that said, you can also expect the ultimate Web3 development platform Moralis (a.k.a. Firebase for crypto) to soon start natively running Ethers.js.

Luckily, you don’t have to worry about the library running in the back when working with Moralis. As long as you are JavaScript-proficient and know how to use MetaMask, you are all set. Just create your free Moralis account and start deploying killer dApps. 

What is Web3.js?

As mentioned above, Web3.js is an open-source library or a collection of JavaScript (JS) libraries. If you can’t answer “what is JavaScript?”, make sure to read our guide on this popular programming language. We’ve also mentioned in the introduction that Web3.js serves for Ethereum-based projects. As such, it enables developers to interact with the Ethereum blockchain when creating dApps. Moreover, it is worth pointing out that the Web3.js library was built by the Ethereum Foundation. Thus, it has a rather large community behind it, which is usually an added value. 

Furthermore, Web3.js essentially incorporates functions for communicating with Ethereum nodes. This communication is performed via the JavaScript Object Notation – Remote Procedure Call (JSON-RPC) protocol. In case this is the first time you’re hearing about Web3, make sure to jump over to our big guide to Web3. Moreover, before taking on our Web3.js vs Ethers.js comparison, we need to ensure you all know what JS modules are. For now, note that both Web3.js and Ethers.js contain modules.

JS Modules Explained

You can think of JavaScript modules as book chapters or sections. Moreover, this principle of compartmentalization is something all experienced programmers apply. As such, you can see many programs and programming libraries divided into modules. And, both ETH JS libraries covered herein follow that practice.

Furthermore, modules are basically clusters of code. So, when the JavaScript programming language is in question, modules represent a cluster of meaningful combinations of words and special characters. Also, keep in mind that each module normally covers specific functionality within a larger program. However, circling back to the book chapter analogy, unlike book sections, good programming modules can be removed, added, or shuffled as necessary. Moreover, all these alterations don’t affect the system as a whole. As such, they are essentially highly self-contained with specific functionality. In addition, dividing programs and libraries into modules also makes maintainability and reusability much simpler. Nonetheless, if you are familiar with any other coding languages (e.g.: Java or Python), you may think of classes. They are a very close analogy to modules.

Web3.js Modules

Now that you know what JS modules are, let’s take a quick overview of Web.js modules:

  • Web3.eth: The Eth module is there for interacting with the Ethereum network. It offers several sub-modules, including Web3.eth.subscribe, Web3.eth.contract, Web3.eth.accounts, Web3.eth.personal, and more.
  • Web3.*.net: The Net module is there for interacting with network properties. Of course, it may be used as a sub-module to interact with Ethereum (Web3.eth.net).
  • Web3.bzz: The Bzz module is there for interacting with the swarm network.
  • Web3.shh: The Shh module is there for interacting with the whisper protocol.
  • Web3.utils: This module provides utility functions for Ethereum dApps and other web3.js packages.

Like with most programming languages, platforms, and libraries, it is best to use their documentation for more details. You can find the link to the Web3.js documentation in the “Web3.js vs Ethers.js – Documentation” section below. 

What is Ethers.js?

Ethers.js is also an Ethereum JavaScript library that enables developers to communicate and interact with the Ethereum network. Moreover, it is an open-source library with the MIT License. So, what’s the point of Ethers.js if it serves the same purpose as Web3.js? Well, keep in mind that having options is normally a good thing. As such, Ethers.js offers an impressive (in many aspects a superior) alternative to Web3.js. However, just like with any product out there, Ethers.js and Web3.js have their own drawbacks and benefits. More on that in the “Web3.js vs Ethers.js – A Comparison” section below.

Ethers.js Modules

Just like Web3.js, Ethers.js also has several modules. To be exact, there are four modules in this JS library: Ethers.contract, Ethers.provider, Ethers.utils, and Ethers.wallets. These modules are the core of the Ethers.js’ API (Application Programming Interface). Moreover, let’s take a quick overview of all four Ethers.js modules:

  • Ethers.Provider: This module enables you to establish a connection with the Ethereum blockchain. You use it to issue queries and send signed transactions. Through this module, Ethers.js users get to change the state of the blockchain.
  • Ethers.Contract: You use this module to deploy and interact with smart contracts. While deploying smart contracts is one of the main purposes of Ethers.Contract, it has more to offer. As such, it also packs functions that enable developers to ‘listen’ to smart contract events (sync and index smart contract events). Furthermore, you also use this module to get information about smart contracts and call particular functions provided by smart contracts.
  • Ethers.Utils: You will use this module when you want to format data and process user inputs. As such, Ethers.utils makes building dApps a whole lot easier.
  • Ethers.Wallet: As you can assume based on the ‘.wallet’, Ethers.Wallet provides a way to connect to any existing Ethereum address (an Ethereum wallet). On top of that important feature, this module also enables you to create new wallets and sign transactions.

For more details regarding Ethers.js main features, check out our Ethers.js vs Web3.js comparison. 

Web3.js vs Ethers.js – ETH JS Libraries Side-by-side

So far we’ve covered the basics of both JS ETH libraries, including their modules. As such, you should have a proper understanding of what Ethers.js and Web3.js are. Also, you now know what they are used for. As such, you understand they are very important for developing dApps on the Ethereum blockchain or other EVM-compatible chains. 

In the following subsection, we’ll cover the main aspects of both JS libraries. As a result, you will be able to use this Web3.js vs Ethers.js comparison to determine which of the two options to use. However, please note that you do not need to overthink this. We assure you that you can work successfully with either of the two JS ETH libraries. This is especially true when using Moralis. Though Web3.js is currently the native choice, we are planning a transition to Ethers.js. However, luckily covering the crypto-related backend using Moralis is as simple as it gets. In most instances, you only need to copy and paste short snippets of code provided by Moralis’ documentation. With that said, let’s do the Web3.js vs Ethers.js comparison.

Web3.js vs Ethers.js – A Comparison

In the subsections that follow, we will compare Web3.js vs Ethers.js in the following aspects:

  • The team behind it
  • Popularity
  • Downloads
  • Updates
  • Testing
  • Web performance
  • Documentation
  • License

Web3.js vs Ethers.js – The Team Behind It

  • Web3.js: It is a project of the Ethereum Foundation (a non-profit organization). With an entire organization behind a project, there are more developers offering support. Unfortunately, this also means that there is no clear responsibility as to who should ensure that all is in order.  
  • Ethers.js: It was developed and is maintained by Richard “RicMoo” Moore. This clearly puts full responsibility on RicMoo.

As you can see, each of the backing types has its pros and cons. What kind of backing do you prefer? 

Web3.js vs Ethers.js – Popularity

Here, you need to keep in mind that Web3.js was created first. As such, it makes sense that it wins the overall use cases title. By leaning on GitHub’s data, Web3.js has more stars and more repositories. On the other hand, when it comes to the speed of growth in popularity, Ethers.js comes on top.

Web3.js vs Ethers.js – Downloads

Another way to compare these two JS libraries is to look at the download. However, the overall number of downloads doesn’t paint a clear picture. Since Web3.js has been on the scene noticeably longer it has an unfair advantage. Luckily, we can rather focus on daily downloads. According to npm-stat.com, Ethers.js is a winner in that aspect.

Web3.js vs Ethers.js – Staying Updated

It is important to go with a library that is updated regularly and properly. That way it ensures that the support team removes all known bugs and adds new features in a timely manner. According to available reviews and devs feedback, both ETH JS libraries are updated relatively regularly. 

Web3.js vs Ethers.js – Testing

When it comes to testing, Ethers.js may be the better choice. It has pre-written tests and clear documentation of its tests. However, you should keep in mind that this conclusion is based on previous versions of the Ethers.js. With the new version, things may be different. 

Web3.js vs Ethers.js – Web Performance

Ethers.js loads slightly faster thanks to its noticeably smaller size, which may offer better performance. Though, the size factor plays a noticeable role only when it comes to small dApps. Also, it is important to point out that there is not sufficient speed test data for the exact same dApps using Web3.js and Ethers.js. Thus, any performance advantage remains to be confirmed.

Web3.js vs Ethers.js – Documentation

According to our experience and comments from developers, we can say that neither of the two ETH JavaScript libraries has perfect documentation. However, they both provide you with more than enough details to get going. Then, it is up to you to cover the key aspects of your interests. This is also the way you will determine, which one better fits your project. Moreover, here are the links to the currently latest versions (at the time of writing) of documentation for each library:

  • The Web3.js documentation: https://web3js.readthedocs.io/en/v1.7.0/
  • The Ethers.js documentation: https://docs.ethers.io/v5/ 

Furthermore, you should also keep in mind that JavaScript itself is always evolving, thus its libraries must be updated as well. Things evolve even faster in the blockchain world. As such, teams release updates and newer visions of both ETH JavaScript libraries quite often. 

Note: At the point of writing Web3.js version is 1.7.0, while Ethers.js is 5.4. Being aware of these versions is important when following certain tutorials. You need to match the version of either of the two ETH JavaScript libraries if creators haven’t updated their tutorials to function with the latest versions.

Web3.js vs Ethers.js – License

  • Web3.js: It has an LGLv3 license.
  • Ethers.js: It has an MIT license. 

If your project has specific requirements regarding the license, you need to pay attention to that. In some cases, it is smart to hire a license expert. A professional will help you determine which of the two ETH JavaScript libraries is more suitable for you.

Web3.js vs Ethers.js – Guide to ETH JavaScript Libraries – Summary

We’ve covered a lot of ground and have managed to wrap up our Web3.js vs Ethers.js comparison. By now you know that both JS ETH libraries offer several modules that enable you to interact with the Ethereum chain. Moreover, you’ve learned that each library has its advantages and disadvantages. However, the blockchain industry as a whole is slowly migrating towards a younger alternative – Ethers.js. This same transition is also in the pipeline for Moralis. Though, this is not something you need to worry about when developing dApps with this ultimate Web3 development platform. You only need to create your free Moralis account, create a Moralis server, and initialize Moralis. One way to do this is to create your HTML and JS code files from scratch. However, you may also use the most practical Ethereum dApp boilerplate. This ultimate Web3 boilerplate enables you to deploy dApps in minutes. 

Furthermore, in case you want to continue your free blockchain development education, make sure to visit the Moralis’ blog and the Moralis’ YouTube channel. You can find a ton of high-quality content there, including many interesting example projects. Some of the latest topics cover NFT API alternatives, gasless transactions, how to build a Web3 login with Web3 authentication, DAO smart contract example, WalletConnects Android SDK, Web3 wallets, GameFi and play-to-earn (P2E), how to interact with smarts contract through a website, Ethereum gas fees, and much more. However, if you are determined to become a blockchain developer sooner rather than later, you may want to consider a more professional approach. If so, you should enroll in Moralis Academy. That way you’ll gain access to many high-quality courses, a remarkable community, and professional mentors. This trio will enable you to go full-time crypto in no time. 

January 19, 2022
Moralis Blog
Moralis Blog
Become a Moralis Mage
Get the latest information about Moralis Web3 in your email
Search
Generic filters
Related Articles
Become a Web3 Expert
Subscribe to our newsletter and get our E-book Web3 Speed run for FREE