December 2, 2022

Full Guide: What is Ethers.js?

Table of Contents

One of the most critical aspects of Web3 JavaScript (JS) development is cross-system intercommunications. When building decentralized applications (dapps) or other Web3 platforms, you need a seamless workflow to connect your projects and the various blockchain networks. In the case of Ethereum development, one such asset is ethers.js. Furthermore, ethers.js is a prominent Web3 library that developers can use to interact with the Ethereum blockchain. As you can imagine, libraries like this play an essential role in Web3 development. So, if you want to learn more about ethers.js, join us in this guide as we cover the ins and outs of this Ethereum library! 

In the initial sections of this article, we will explore the intricacies of ethers.js. In doing so, we cover some of the library’s most prominent features and modules. Once you gain a better understanding of ethers.js, we will briefly cover Web3.js and compare the two to highlight the differences and similarities between them. Lastly, to top things off, the last section covers a prominent ethers.js alternative: the Moralis Streams API! 

The aforementioned interface is one of Moralis’ outstanding Web3 APIs, enabling anyone to easily stream blockchain data into the backend of any application via Web3 webhooks. Other noteworthy Moralis development tools include the Auth API, NFT API, Token API, etc. These tools contribute to a more accessible Web3 developer experience, which is why Moralis presents the fastest way to build a Web3 app

Moralis

If this sounds exciting and you want to access these Web3 development features, sign up with Moralis. You can create an account entirely for free and leverage blockchain technology’s full potential in no time. So, set up your account immediately; it only takes a couple of seconds! 

What is Ethers.js? 

Ethers.js is a Web3 JavaScript (JS) library released in 2016 and created by Richard Moore. It is one of today’s most popular open-source Ethereum JS libraries, featuring millions of downloads. Much like conventional programming libraries, ethers.js consists of a collection of prewritten code snippets that can be reused to perform essential everyday functions. However, ethers.js is, unlike other traditional libraries, Web3-based. Also, developers can use this library to easily communicate and interact with the Ethereum blockchain. 

a cloud on top of the ethers.js title

Ethers.js was initially designed for “ethers.io. However, it has expanded to become a more general-purpose library. Furthermore, ethers.js features a small bundle size, extensive and straightforward documentation, a user-friendly API structure, and is written in TypeScript. Consequently, it is a highly attractive library for many Web3 developers as it is intuitive and straightforward to use. 

What’s more, to better understand the utility of ethers.js, let us take a closer look at some of the library’s key features: 

  • Size – Ethers.js is tiny, only 88 KB compressed and 284 KB uncompressed.
  • ENS – Ethereum Name Service (ENS) names are first-class citizens. Consequently, they can be used wherever Ethereum addresses can be used.
  • Test Cases – Ethers.js features an extensive collection of test cases that are actively maintained and updated.
  • MIT License – The library is entirely open-source, including all dependencies. 
  • Security – With ethers.js, you can keep your private keys safe and secure. 

The features above are only five prominent examples, and ethers.js has much more to offer. As such, there is more for you to discover on your own. However, some essential components of ethers.js we need to explore further in this guide are its various modules. In turn, we’ll understand how the library works.

Library Modules 

Before exploring ethers.js modules, let us briefly recap what JS modules are in the first place. A module is a function or a collection of similar functions created to better structure/organize a codebase. What’s more, modules are generally independent, specific, and reusable. Now, with a brief overview of what modules are, let us jump straight into ethers.js! 

white background with the ethereum logo and title next to each other

Ethers.js features four central modules: “ethers.contract“, “ethers.utils“, “ethers.wallets“, and “ethers.provider“. These modules are at the core of ethers.js’ application programming interface (API). Consequently, let us break down each module separately to get a quick overview of their purposes: 

  • ethers.contract – The central purpose of the “ethers.contract” module is to provide the ability to deploy Ethereum smart contracts seamlessly. However, even though this is the module’s main functionality, it has more to offer. For example, you can use “ethers.contract to listen to smart contract events, call functions, query information regarding contracts, and more.
  • ethers.utils – You can use “ethers.utils” for both processing user inputs and formatting data. These are two vital Web3 development tasks, meaning that this module makes blockchain development more accessible.
  • ethers.wallet” – With the “ethers.wallet” module, you can easily connect to existing wallets (Ethereum addresses), create new wallets, and sign transactions.
  • ethers.provider” – With the “ethers.provide” module, you can seamlessly establish a connection with the Ethereum network. What’s more, you can utilize this module to query on-chain data and send signed transactions. As such, through this module, you can alter the state of the Ethereum blockchain with ethers.js! 

That covers the essentials of ethers.js! In the following section, we will look closely at web3.js to learn how these libraries differ and explore what makes ethers.js unique! 

What is Web3.js? 

Web3.js is – just like ethers.js – an open-source JS library facilitating seamless interactions with the Ethereum blockchain. Furthermore, the Ethereum Foundation created Web3.js. As such, it has the backing of a rather extensive community, which adds value to this library. Moreover, Web3.js has been around since 2015, meaning that this is a battle-tested library used in many prominent projects. 

web3.js in grey and orange lettering

Web3.js establishes the communication with Ethereum nodes through the JSON-RPC (”JavaScript Object Notation – remote procedure call”) protocol. Furthermore, much like ethers.js, this library also features modules. Specifically, it has five modules in total: 

  • web3.eth“ – This is the module for interacting with the Ethereum network. What’s more, it offers additional sub-modules like “web3.eth.contract,web3.eth.subscribe,web3.eth.accounts“, etc.
  • web3.net“ – You can use “web3.net“ to interact with network properties.
  • web3.shh – With the “web3.shh“ module, you can interact with the Whisper protocol. 
  • web3.utils“ – The “web3.utils“ module provides utility functions for Ethereum dapps and other packages.
  • web3.bzz“ – You use “web3.bzz“ to interact with the Swarm network.

Based on the overviews of ethers.js and web3.js, you might have noticed that these libraries are quite alike and serve similar purposes. Consequently, the following section compares the two, highlighting the differences between them! 

Ethers.js vs Web3.js 

If you have followed along this far, you should now be familiar with ethers.js and Web3.js. In turn, you are now acquainted with the libraries’ various modules, key features, and how developers can use them. You also understand that Web3 libraries like these are vital in blockchain development as they allow developers to save vast amounts of time and resources. 

ethers.js vs web3.js

However, you might also have noticed that they serve similar purposes and are quite alike. As such, this section compares ethers.js and Web3.js to highlight some significant differences. By doing so, you will hopefully have an easier time choosing which one to go for in your development endeavors. 

There are various ways in which to compare the two libraries; however, for this guide, we will focus on community, documentation, and popularity:

  • Underlying Community – Web3.js is, as was previously mentioned, an Ethereum Foundation project. Accordingly, it means that Web3.js is directly supported by the organization and is maintained by ChainSafe. On the contrary, ethers.js was built by a single individual called Richard Moore, and a much smaller team of developers maintains this library. 
  • Documentation – Ethers.js and Web3.js both have comprehensive documentation. However, in this aspect, it seems like ethers.js has a slight edge based on the extensive and beginner-friendly ”Getting Started” guide. 
  • Popularity – Web3.js is currently the largest of the two Ethereum JS libraries. However, ethers.js is presently growing at a rapid rate based on weekly downloads. However, in terms of GitHub stars, Web3.js exceeds ethers.js by more than 10,000. 

Nevertheless, both ethers.js and Web3.js have their pros and cons. Consequently, it is up to you to choose between them depending on your needs as a developer! 

Exploring Ethers.js Alternatives

In addition to the aforementioned libraries, there are other ways to interact with the Ethereum blockchain, and a great example is Moralis’ Web3 Streams API! With the API, you can seamlessly stream on-chain data into the backend of your applications via Moralis webhooks. What’s more, because of Moralis’ cross-chain capabilities, you don’t have to limit yourself to the Ethereum network. In fact, you can set up streams for multiple leading programable blockchains. This includes Polygon, Avalanche, BNB Chain, Cronos, Fantom, and many more! As a result, you can future-proof all of your blockchain projects!

announcement of moralis launching streams api, the ultimate ethers.js alternative

From a conventional perspective, it has always been a cumbersome task to query blockchain networks for data. However, this is no longer the case, thanks to Moralis! With the Streams API, you can avoid tasks such as connecting and maintaining RPC nodes, wasting time building complicated data pipelines, setting up unnecessary abstractions, etc. Instead, you can save time and focus on creating more value for your customers. 

As a result, you can easily set up streams to receive Web3 webhooks on several networks and layer-2 (L2) platforms whenever: 

  • Someone partakes in a token sale
  • Particular assets are sent, swapped, received, or staked
  • A certain address sends or receives assets
  • A battle starts in an online Web3 game
  • Or other smart contract events trigger based on your filters

What’s more, thanks to the accessibility of the Streams API, you can set up streams in only five straightforward steps: 

  1. Provide an address
  2. Apply filters to specify when to receive webhooks
  3. Specify the chains you are looking to monitor
  4. Add your webhook URL
  5. Receive webhooks

Next Steps

If you want more information on how to set up Web3 streams with Moralis, check out our guides on Ethereum webhooks and Polygon webhooks. These articles provide comprehensive tutorials for setting up Web3 webhooks for various chains! In addition, If you’d like to explore how Moralis – the ultimate Web3 provider – enables developers to get wallet balance, including native and ERC20 token from address, make sure to read our article exploring the best ERC20 token balance API! Additionally, if you want to add scalable Web3 infrastructure to your project, Moralis is your go-to option. In fact, Moralis is trusted by industry leaders, including MetaMask, 1inch, SuperFarm, and many others! On average, projects save $86.4 million in engineering costs and a whopping 87% reduction in time-to-market!

Portrait of the co-founder of Polygon Network and a testimonial statement from using Moralis as blockchain infrastructure.

Summary – What is Ethers.js? 

Ethers.js is one of the most well-used Ethereum JavaScript (JS) libraries with the central purpose of facilitating seamless communications and interactions with the Ethereum blockchain. Using TypeScript, the library was born and features intuitive documentation, small bundle sizes, and a user-friendly API structure. As such, it is quite easy to grasp ethers.js, making it a top choice for Web3 developers worldwide. Furthermore, ethers.js has four primary modules: “ethers.contract“, “ethers.utils“, “ethers.wallets“, and “ethers.provider“. These components are the very core of the library’s API and are vital in how it works. Moreover, some of the main features of ethers.js are its small size, ENS support, extensive set of test cases, etc. 

An exciting ethers.js alternative is Moralis’ Web3 Streams API. With this interface, you can easily set up Web3 webhooks to easily stream on-chain data into the backend of any project. As such, with Moralis, you can create dapps more effectively and efficiently by fully leveraging the power of blockchain technology. 

If you liked this tutorial, consider checking out more articles here at Morals’ Web3 blog. For instance, read our guides on the Goerli testnet, how to create an AWS Lambda function, what the next-gen L2 chain – the Palm network – entails, and much more! The blog features fresh and exciting Web3 development content for both new and experienced developers.

Moreover, if you want to become a more proficient Web3 developer, consider enrolling in Moralis academy. The academy offers a selection of informative and exciting blockchain development courses. For example, check out ”Blockchain & Bitcoin Fundamentals” to learn the basics of the blockchain industry! 

moralis academy

Nevertheless, no matter your Web3 ambitions, sign up with Moralis to access the most seamless Web3 developer experience. Creating an account is free, so you have nothing to lose! 

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
September 12, 2022

How to Build a Cronos Dapp in 5 Steps

October 15, 2022

NodeJS Web3 Tutorial – Create Dapps Using a NodeJS Web3 Example

January 22, 2024

Full Guide – The Ethereum Ecosystem in 2024

November 2, 2023

Create Chiliz Chain Dapps with Moralis’ Chiliz API 

October 7, 2022

Cronos Development – Connect Dapps to Cronos

August 11, 2022

How to Code a Blockchain App in 5 Steps

October 13, 2022

Cronos Boilerplate – How to Create Cronos Dapps

November 28, 2022

Palm Blockchain – What is the Palm Network?

December 7, 2023

Which is the Best Crypto Exchange API for Web3 Developers?