Whether or not you’re a developer needing a refresher on Web3 libraries or are at the moment transitioning from Web2 to Web3 and need assistance understanding which Web3 library would profit you probably the most, you’ve come to the fitting place! Along with exploring the highest Web3 libraries, we’ll additionally have a look at a substitute for these libraries providing a superior resolution: Moralis. Now, since ethers.js is among the hottest Web3 libraries, we’ll evaluate ethers.js vs Web3 streams, displaying the ability of the Moralis Streams API! For example, when working with Moralis’ JS SDK, these are the strains of code that do the trick:
Moralis.begin({ apiKey: course of.env.MORALIS_KEY, }).then(async () => { const stream = await Moralis.Streams.add(choices) const {id} = stream.toJSON(); await Moralis.Streams.addAddress({id, handle }) });
If you wish to discover ways to correctly implement the above snippet of code, ensure to dive into the “Web3 Libraries Instance” part. That is the place we’ll additionally present you the right way to receive your Web3 API key. When you’re prepared, create your free Moralis account and comply with our lead!

Overview
In at this time’s article, we’ll first do an outline of the main Web3 libraries. This can assist you to decide which ones may be value your consideration. As identified above, ethers.js has develop into the preferred Web3 library. As such, we’ll proceed by specializing in evaluating the ethers.js Web3 library with the Web3 Streams API from Moralis. This comparability will clearly point out how one can take the trail of least resistance and be part of the Web3 revolution along with your legacy expertise.
For many who might not but be accustomed to Web3 libraries, we’ll additionally clarify what they’re. Final however not least, we’ll dig a bit deeper into the perfect different to our highlighted Web3 libraries. That is the place you’ll have a chance to study extra in regards to the Streams API and different Moralis instruments. Then, you’ll be prepared to begin constructing dapps the straightforward approach!

Listing of Web3 Libraries
Because the above picture signifies, among the main Web3 libraries are:
- Libp2p
- Web3j
- Web3.js
- Web3.py
- Ethers.js
You might need observed the sunshine.js library within the above picture however not in our record. That’s as a result of that library is deprecated. Due to this fact, we received’t discover this library any additional. Now, let’s cowl every of the above 5 libraries in additional element!
Libp2p
“Library peer-to-peer,” or “libp2p,” is greater than a Web3 library. It’s a peer-to-peer (P2P) networking framework – a group of specs, protocols, and libraries. The framework facilitates P2P communication between community individuals (a.okay.a. “friends”) and permits the event of P2P functions.

Libp2p began as IPFS’ (InterPlanetary File System) wire protocol. Nonetheless, it phased out into an impartial networking layer, which offers a set of specs that many protocols can undertake. This enables libp2p apps to function in various runtimes and networking environments. As an example, IPFS makes use of the Golang implementation of libp2p, however Polkadot makes use of the Rust implementation of this library. So, libp2p handles the peer discovery and communication within the Polkadot ecosystem. As well as, in accordance with Polkadot’s official web site, libp2p is positioned to be the usual for future dapps.
Following are among the key benefits of libp2p as listed on this framework’s documentation:
- Modularity – Permits builders to combine and match totally different parts to accommodate the wants of their apps.
- Intensive Transport “Configurability” – By supporting numerous transport protocols, libp2p functions can function in numerous runtime and networking environments.
- Versatility – Provides a spread of discovery mechanisms and knowledge storage/retrieval patterns and is implementable in lots of programming languages.
- Safety – Contains a number of security measures.
- Robustness – Designed to resist stress, disturbance, and alter. Additional, it could possibly get well rapidly from disruptions or failures.
- Resiliency – Even when some friends are offline or unreachable, the community stays out there and accessible.
- Effectivity – Makes it doable to retailer and retrieve knowledge in a cheap and scalable approach.
- Piercing NAT Boundaries – With capabilities for NAT traversal, libp2p maintains the connectivity of the community and ensures that it stays accessible regardless of the presence of firewalls or NAT gadgets.
- Interoperability – Implementations in several programming languages and variations are interoperable with each other.
- Decentralization – Working with out a government.
Web3j

Web3j is a extremely modular, reactive, type-safe Java and Android library for the Ethereum community. It lets you work with sensible contracts and work together with Ethereum shoppers (nodes) (see the above picture) with out writing your personal integration code.
Like all main Web3 libraries, web3j helps Ethereum wallets and the implementation of Ethereum’s JSON-RPC consumer API through HTTP and IPC. It additionally options an auto-generation of Java sensible contract wrappers. This implies you possibly can create, deploy, transact with and name sensible contracts from native Java code. Web3j additionally helps Solidity and Truffle definition codecs.
This library lets you work with filters utilizing its reactive-functional API. Web3j additional helps Ethereum Title Service (ENS), OpenEthereum’s and Geth’s private consumer APIs, node suppliers (Alchemy and Infura), ERC-20 and ERC-721 token requirements, and JP Morgan’s Quorum through “web3j-quorum.”
The Web3j Ethereum Java library additionally contains complete integration checks, command line instruments, and Android compatibility. In case you are excited by studying extra about this library and dealing with it, go to the official web3j documentation.
Web3.js
Web3.js is an open-source JavaScript (JS) library created by the Ethereum Basis. The principle objective of Web3.js is to facilitate seamless interactions with the Ethereum chain. This interplay is feasible through communication with Ethereum nodes, which works by way of the JSON-RPC protocol. The core of Web3.js are the next 5 modules:
- “web3.eth“ – It facilitates interplay with the Ethereum community through a number of sub-modules (“web3.eth.contract,“ “web3.eth.subscribe,“ “web3.eth.accounts,“ and many others.).
- “web3.web“ – Facilitates interplay with community properties.
- “web3.shh“ – It facilitates interplay with the Whisper protocol.
- “web3.utils“ – Gives entry to features for Ethereum dapps and different packages.
- “web3.bzz“ – It facilitates interplay with the Swarm community.

As soon as we cowl ethers.js (under), you’ll understand that these two Web3 libraries are fairly comparable. Despite the fact that they each serve the identical objective, there are a number of distinct variations between the 2. Furthermore, if you’re excited by studying extra about these distinct variations, ensure to take a look at our Web3.js vs ethers.js comparability. For extra particulars, go to the official Web3.js documentation.
Web3.py
In case you are Python proficient, you should utilize the Web3.py library to affix the Web3 revolution. As “.py” signifies, this Web3 library helps the Python programming language for interactions with the Ethereum chain. So, whether or not you wish to ship transactions, learn block knowledge, work together with sensible contracts, or extra, Web3.py has your again.

Similar to Web3.js, Web3.py communicates with the Ethereum community utilizing the JSON-RPC protocol. The latter permits the Web3.py library to make requests to Ethereum nodes and write and browse knowledge on the Ethereum blockchain. The idea behind this communication is very like making HTTP requests to JSON APIs on net servers.
It’s value declaring that Web3.py’s software programming interface (API) originates from the above-described Web3.js. In fact, by way of time, Web3.py has advanced to develop into extra tailored for Python improvement. Nonetheless, there are numerous similarities between the 2 Web3 libraries. As such, it may be of nice worth to go over the Web3.py vs Web3.js comparability as nicely. That’s very true if you’re JavaScript and Python proficient. Nonetheless, if Python is your most well-liked programming language, you need to concentrate on Ethereum Python implementation.
Ethers.js
As talked about above, similar to Web3.js, ethers.js is a JS library aiming to be an entire and compact resolution for Ethereum improvement. This library entered the scene a few 12 months after Web3.js. Nonetheless, regardless of its latter arrival, it has managed to develop into the preferred Web3 library.

Other than JavaScript assist, ethers.js additionally contains utility features in TypeScript (TS). A few of its primary benefits embody a substantial assortment of maintained take a look at circumstances, preserving non-public keys in your consumer protected and sound, and the flexibility to create JavaScript objects from any contract ABI, together with ABIv2 and the ethers Human-Readable ABI with meta courses. Different vital advantages of ethers.js embody the next:
- Importing and exporting JSON wallets (e.g., Geth and Parity).
- Helps use of ENS names anyplace Ethereum addresses can be utilized.
- Importing and exporting BIP 39 mnemonic phrases (twelve-word backup phrases) and HD wallets in a number of languages.
- A number of methods to connect with Ethereum nodes (JSON-RPC, Etherscan, MetaMask, Infura, Alchemy, or Cloudflare).
- Compact dimension.
- Absolutely TypeScript prepared – it contains definition information and full TS sources.
- An open-source MIT license that features all dependencies.
Due to all these advantages, ethers.js dapp improvement actually took off in 2022, with greater than 900,000 downloads. Nonetheless, we consider there may be a fair higher approach to fetch on-chain knowledge and take heed to on-chain occasions. However we wish you to find out for your self whether or not you like working with ethers.js occasions or the Moralis Streams API. As such, ensure to discover the upcoming Web3 libraries instance.
Web3 Libraries Instance – Ethers.js vs Web3 Streams
The above video exhibits you the right way to take heed to occasions utilizing ethers.js and the right way to do the identical with the Moralis Streams API. Within the case of ethers.js, the “getTransfer()” perform does a lot of the job. Throughout the perform, we offer a contract handle we wish to take heed to, a supplier, and outline the sensible contract’s occasion that we wish to concentrate on (“Switch” in our case). Right here’s the complete script that will get the job performed utilizing ethers.js:
const ethers = require(“ethers”); const ABI = require(“./abi.json”); require (“dotenv”).config(); async perform getTransfer(){ const usdcAddress = ”0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48”; const supplier = new ethers.suppliers.WebSocketProvider( ‘wss://eth-mainnet.g.alchemy.com/v2/${course of.env.ALCHEMY_KEY}’ ); const contract=new ethers.Contract(usdcAddress, ABI, supplier); contract.on(“Switch”, (from, to, worth, occasion)=>{ let transferEvent ={ from: from, to: to, worth: worth, eventData: occasion, } console.log(JSON.stringify(transferEvent, null, 4)) }) } getTransfer()
Right here’s the format during which you’ll see the lead to your terminal after operating the above script:

Observe: Your precise outcomes received’t match those above however the present stay transactions.
Trying on the above screenshot, you possibly can see that the information shouldn’t be parsed. This implies you might want to additional course of the outcomes earlier than you possibly can make the most of them in your dapp. Happily, that’s not the case once we use the Moralis Streams API.

Web3 Libraries – The “Killer” Various
On this part, you’ll lastly discover ways to correctly implement the snippet of code offered within the introduction of at this time’s article. If you wish to use the next script to pay attention for on-chain occasions, you might want to receive your Moralis Web3 API key. The latter awaits you inside your admin space, which you’ll be capable of entry along with your free account:
Then, save your API key inside your “.env” file below the “MORALIS_KEY” variable. Subsequent, you should utilize our script under.
First, we have to import Moralis, EVM-compatible chains, and the ABI, and require “dotenv”:
const Moralis = require("moralis").default; const Chains = require("@moralisweb3/common-evm-utils"); const EvmChain = Chains.EvmChain; Const ABI = require(“/abi.json”); require("dotenv").config();
With the above strains in place, we will outline our stream’s choices:
const choices = { chains: [EvmChain.ETHEREUM], description: "USDC Transfers", tag: "usdcTransfers", includeContractLogs: true, abi: ABI, Topic0: [“Transfer(address, address,uint256)”], webhookUrl: "your webhook url - use" };
Lastly, we get to implement the snippet of code from the intro and add the USDC sensible contract handle:
Moralis.begin({ apiKey: course of.env.MORALIS_KEY, }).then(async () => { const stream = await Moralis.Streams.add(choices) const {id} = stream.toJSON(); await Moralis.Streams.addAddress({ id: id, handle: [”0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48”] }) });
With the entire above strains of code in place, we’re able to run the script, which returns parsed on-chain knowledge:

The above-created stream additionally seems in our admin space. The “Streams” tab of the admin space can also be the place the place we will pause, edit, or delete any present stream:
Because the “New Stream” button signifies, that is additionally the place the place we will create new streams utilizing the admin UI. The latter takes us by way of the steps to arrange choices (like within the code above).
What are Web3 Libraries?
Web3 libraries are programming libraries that target Web3 improvement. They’re collections of non-volatile assets that programmers can use for constant and extra user-friendly coding of scripts that indirectly work together with blockchain networks. These assets can embody configuration knowledge, documentation, assist knowledge, message templates, pre-written code and subroutines, courses, values or sort specs, and extra.
Ethereum continues to be the main programmable blockchain and, due to this fact, the guts of Web3 improvement. Plus, many different blockchains comply with Ethereum’s lead by being EVM-compatible. This additionally means they will use the identical improvement instruments. As such, most Web3 libraries concentrate on Ethereum. Nonetheless, a Web3 library can goal another blockchain community (non-public or public) and any programming language.

Programming Languages for Web3 Libraries
When you lined the above-presented Web3 libraries, you now know that JavaScript, Python, and Java are the programming languages behind the preferred libraries and likewise their options. This additionally tells you that Web3 libraries assist legacy devs use their Web2 proficiency to enter dapp improvement. As an example, within the case of Polkadot and Solana, Rust could be the language to make use of.
Nonetheless, you most likely know that sensible contracts are an important a part of Web3 expertise. As you progress, it’s possible you’ll develop into excited by creating superior and distinctive sensible contracts. In that case, the aforementioned Web3 programming languages is probably not sufficient. Positive, there are already some methods to create sensible contracts with legacy languages, however Solidity is the main selection amongst sensible contract programming languages.
If you wish to discover how one can make the most of your legacy expertise, ensure to take a look at our articles displaying the right way to create an ERC721 token or ERC1155 token. Additionally, see the right way to sort out the “create ERC20 token” quest!
Web3 Libraries Various
When you took on the above instance, you already had a chance to get acquainted with the Moralis Streams API. You realized that it’s the final software to take heed to any sensible contract or pockets handle. You additionally came upon which you could create new streams utilizing the Moralis admin UI or Moralis’ SDK. Basically, Moralis Streams allow you to stream blockchain knowledge into your backend through webhooks. Moreover, since Moralis helps all of the main blockchains, you are able to do this on Ethereum, Polygon, Avalanche, BNB Chain, Fantom, Cronos, all testnets, and different networks. To discover the Moralis Streams API additional, use the “Streams API” hyperlink within the intro.
Other than listening to sensible contracts and wallets, you should utilize Moralis to implement Web3 authentication with a single line of code. Additionally, with the Moralis Web3 Knowledge API, you possibly can rapidly fetch any on-chain knowledge. This toolset offers you with every part you might want to create killer dapps – from Web3 wallets to Web3 video games and every part in between. So, in case you haven’t performed so but, create your free Moralis account and begin BUIDLing!
Web3 Libraries – Abstract
In at this time’s article, you had an opportunity to fulfill all of the main Web3 libraries. As such, you now know that web3j, Web3.js, Web3.py, and ethers.js stand out. Alongside the way in which, we additionally answered, “what’s ethers.js?” That is additionally the place you found that ethers.js is arguably the preferred Web3 library. Then, you had a chance to tackle our instance, the place we in contrast ethers.js with the Moralis Streams API. Consequently, you now know what the perfect technique is whenever you wish to take heed to on-chain occasions.
Shifting ahead, you possibly can concentrate on tackling your personal dapp concepts utilizing the information and expertise obtained herein. Nonetheless, in case you want extra apply and steerage, or wish to spark some artistic considering, ensure to make use of Moralis’ assets. The Moralis documentation, our Web3 improvement video tutorials, and our crypto weblog are all you might want to develop into a Web3 developer totally free. There, you may as well discover different sensible instruments, resembling a gwei to ether converter and a dependable crypto faucet. In fact, you may as well take a extra skilled method to your blockchain improvement schooling by enrolling in Moralis Academy. In that case, ensure to begin with blockchain and Bitcoin fundamentals.