June 18, 2024

Streams Vs. Ethers.js – The Best Way to Get Real-Time Web3 Data

Table of Contents
Check out Moralis´ Streams API for the best way to work with real-time blockchain data!

Are you looking for the easiest way to integrate real-time data into your decentralized applications (dapps)? If so, you’ve come to the right place. In today’s guide, we’ll introduce you to Moralis’ Streams API—the ultimate tool for monitoring blockchain events. In doing so, we’ll compare the Streams API with Ethers.js to highlight why the former is the better option for you when you need to get real-time Web3 data. For a quick overview, check out the comparison table below:

Streams vs Ethers.js comparison table.

For a detailed breakdown of the table above, further information on Ethers.js and the Streams API, and a step-by-step tutorial on using these tools, join us in this guide as we lay it all out for you. Alternatively, you can watch the comprehensive Moralis YouTube video linked below:

Ready to start using the Streams API right away? Sign up for free with Moralis to gain instant access to our suite of top-tier development tools!

Want to Use the Industry's
Leading Web3 APIs?

Overview

One way to get real-time Web3 data is to leverage Ethers.js, a prominent JavaScript library for building blockchain-based projects. However, setting up on-chain event listeners with Ethers.js can be complex, time-consuming, and costly. Luckily, there is a more efficient alternative: the Moralis Streams API!

Moralis logo.

The Streams API significantly simplifies the process of getting real-time Web3 data. With our user-friendly interface, you can effortlessly track any on-chain event for any wallet, address, or asset with just a few clicks. Curious to learn more about the Streams API, how it works, and why it’s a game-changer compared to Ethers.js? In this comprehensive guide, we’ll delve into all these aspects and more. Let’s get started!

What is Ethers.js?

Ethers.js is a compact and complete JavaScript library for building dapps. Like conventional programming libraries, Ethers.js offers a collection of prewritten code snippets that perform essential everyday functions, helping developers avoid duplicating effort when creating blockchain-based projects. As such, Ethers.js streamlines Web3 development, allowing users to seamlessly interact with the Ethereum network and its extensive ecosystem. 

Monitor with Ethereum logo and Ethers.js code.

What are some of the core features and benefits of Ethers.js?

  • Lightweight: The Ethers.js library is compact, with a size of ~88kb when compressed and ~284kb uncompressed, making it ideal for dapps where fast load times are crucial.
  • Comprehensive Functionality: Despite its small size, Ethers.js delivers extensive functionality for interacting with the Ethereum network, including wallet creation, contract interaction, message signing, and more.
  • Event Listeners: Ethers.js allows developers and applications to listen to smart contract events, facilitating responsive and dynamic dapp experiences.

Now that we have an overview of what Ethers.js is and its benefits, let’s also dive into some of the library’s limitations!

Exploring the Limitations of Ethers.js

While Ethers.js can be used to get real-time Web3 data, it may not always be the ideal choice. Here are three fundamental limitations of Ethers.js:

  • Setup Complexity: Configuring data pipelines with Ethers.js is often a cumbersome and intricate process. It requires a substantial amount of code, and developers must devise methods to monitor each event, contract, or asset they want to track. This makes the setup both time-consuming and resource-intensive.
  • Unstable & Unreliable: When using Ethers.js to get real-time Web3 data, developers interact directly with RPC nodes. If they choose an unreliable provider, the nodes can be quite unstable, especially for newer blockchain networks. Additionally, if an event is missed for any reason, Ethers.js lacks native mechanisms to deliver it retroactively.
  • Raw Data: Ethers.js returns raw, undecoded data. As such, the responses typically include basic information like block numbers, transaction hashes, etc. To obtain additional information, developers must use various third-party APIs, adding to the complexity.
Ethers.js data pipeline.

So, what is the alternative?

Well, you can now streamline the process of listening to on-chain events with Moralis’ Streams API!

The Ultimate Ethers.js Alternative – Exploring Moralis’ Streams API

Moralis’ Streams API is the ultimate tool for streaming real-time on-chain data directly into your dapps. With our user-friendly point-and-click interface, setting up Web3 data pipelines is effortless, allowing you to receive instantaneous updates on any wallet or contract event via webhooks as soon as they occur.

Text: "Streams API"

The Streams API is a highly dynamic and comprehensive solution, supporting over 44 million contracts across all major chains, including Ethereum, Polygon, BNB Smart Chain (BSC), and many more. This powerful interface covers all types of events, tokens, wallets, DeFi platforms, and more, providing you with everything you need in terms of real-time Web3 data.

By leveraging the Streams API, you can seamlessly integrate real-time alerts into your dapps, keep your databases populated with the latest data, and enhance your projects with current, actionable insights.

Now that you have an overview of Moralis’ Streams API, let’s explore the benefits of this premier tool! 

Benefits of Moralis’ Streams API

So, why are developers choosing to leverage Moralis’ Streams API instead of Ethers.js to get real-time Web3 data? To answer this question, let’s explore five benefits of this industry-leading tool: 

  • Effortless Setup: The Streams API provides an intuitive interface, allowing you to monitor events for any wallet, address, or asset with just a click. Additionally, you can track multiple events in a single stream, including ERC-20 transfers, native transactions, internal transactions, and more.
  • Cross-Chain Support: Moralis supports over 30 blockchain networks and counting. With the Streams API, you can seamlessly add and remove chains from your streams at the click of a button.
  • Comprehensive Data: With Moralis’ Streams API, you receive fully decoded data straight out of the box. Each response is enriched with address labels, token logos, balances, metadata, and much more.
  • Scalability: The Streams API is the most scalable solution for real-time data. Monitor one to 100 million addresses in the same stream and add or remove any address on the fly without breaking a sweat.
  • 100% Delivery Guarantee: If your infrastructure is down for any reason, Moralis will keep all failed deliveries in a backlog. You can replay each event from there, ensuring you never miss an on-chain event again.

Full Comparison: The Best Way to Get Real-Time Web3 Data – Moralis Streams API Vs. Ethers.js

Now that you have an overview of both Ethers.js and Moralis Streams, let’s compare the two to highlight why you should use Moralis to get real-time Web3 data: 

Streams vs Ethers.js comparison table.

Tutorial: How to Get Real-Time Web3 Data with Moralis Streams

In this section, we’ll show you how to seamlessly get real-time Web3 data with Moralis Streams. Specifically, we’ll demonstrate how to monitor USDC transactions in eight straightforward steps:

  • Step 1: Sign up for free with Moralis, log into your account, navigate to the “Streams” tab, and click the “+ Create Stream” button:
Arrows pointing at "Streams" tab and "+ Create Stream" button.
  • Step 2: Provide a name for your stream and select the type of events you want to monitor. For this tutorial, choose “Contract Events”:
"Contract Events" box checked.
  • Step 3: Specify the smart contract events you want to track. In this case, select “Common Events” followed by “Token Transfers”:
"Token Transfers" option checked.
  • Step 4: Assign a tag to your stream and select additional relevant information you want to include in the responses:
Additional data step.
  • Step 5: Input the contract address(es) you wish to monitor. For this tutorial, we’ll use the USDC contract:
USDC contract address added to input field.
  • Step 6: Choose the chain(s) you want to track. We’ll select Ethereum, but you can monitor any network(s) you prefer:
Chain selector.
  • Step 7: Test your stream to ensure everything works as intended (optional):
Testing step.
  • Step 8: Add your webhook URL, hit the “Continue” button, and click “Save & Deploy”:
Arrows pointing at "Webhook URL" field, "Continue" button, and "Save & Deploy" button.

Once deployed, you’ll receive real-time updates sent to your webhook destination whenever there’s a new USDC transfer. Here’s an example of what the response might look like:

//...
{
  transactionHash: '0x1a3807aa7f7d1f4806245115d7b8a32ec105ce20f2b4a8ca31f9a305127c0201',
  logIndex: '409',
  contract: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
  triggered_by: [Array],
  from: '0x47fbac3d17dcd481c3bb428adde4272b458cf724',
  to: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8',
  value: '5187003613',
  tokenName: 'USD Coin',
  tokenSymbol: 'USDC',
  tokenDecimals: '6',
  valueWithDecimals: '5187.003613',
  possibleSpam: false
},
/...

Congratulations! You now know how to get real-time Web3 data with Moralis Streams. From here, you can use these steps to monitor any custom event, wallet, or contract on any blockchain!

For a more detailed breakdown of the steps and practical examples of using the Streams API, please watch the Moralis YouTube video below:

Streams API Use Cases

Moralis’ Streams API offers exceptional flexibility, making it suitable for various use cases. Here are a few noteworthy examples:

  • Notifications: Set up real-time alerts to keep your dapp users informed about their wallet holdings. Notify them instantly about events such as price fluctuations, token transfers, staking rewards, and more. The Streams API is the perfect tool for boosting user engagement in your projects.
  • Populate Databases: Track, index, and store on-chain events in real time. Maintain an accurate and comprehensive record of activities related to any wallet, contract, address, or asset. This ensures your databases remain reliable and up-to-date.
  • Track Token Balances: Monitor, update, and display the balances of users’ wallets in real time within your projects. This is perfect for implementing features like token gating. 
Ethereum data pipeline.

The examples above are only a selection of notable use cases. Thanks to the Streams API’s exceptional versatility, it can be customized for a wide range of additional applications!

Beyond Streams & Ethers.js – Diving Deeper Into Moralis’ Web3 APIs

Moralis is the leading data provider in Web3, offering top-tier nodes and APIs to enhance your developer experience. Our suite of advanced development tools includes over ten specialized interfaces, such as the Wallet API, Token API, NFT API, and Streams API. As such, when leveraging Moralis, you can build cryptocurrency wallets, decentralized exchanges (DEXs), and everything in between without breaking a sweat!  

Moralis logo.

But what makes our APIs the best in the business? 

  • Comprehensive: Our APIs are outcome-driven, providing extensive data with minimal calls. Access both on-chain and off-chain data in a single request, enabling you to build dapps more efficiently.
  • Cross-Chain Compatibility: Simplify your development process with APIs that support multiple chains. Build dapps on Ethereum, Polygon, BSC, and more networks using one unified toolkit.
  • Secure: Enjoy enterprise-grade data security with Web3’s only SOC 2 Type 2 certified infrastructure provider.

Now, to further highlight the power of Moralis, let’s dive into our Web3 API suite! 

Moralis’ Web3 API Suite

Our suite of premier APIs features over ten use case-specific interfaces. And while we can’t cover them all in this guide, we’ll highlight three key examples you’ll likely find helpful when building dapps:

  • Wallet API: The Wallet API is a cutting-edge interface for building wallets and integrating wallet functionality into dapps. With the Wallet API, you can easily retrieve any wallet’s history, net worth, profitability, token balances, and more with just a few lines of code.
Text: "Wallet API"
  • Token API: The Token API is your go-to interface for ERC-20 data, ideal for developing DEXs, token explorers, and similar applications. This intuitive API allows you to seamlessly fetch token balances, metadata, prices, and much more, simplifying your development process.
Text: "Token API"
  • NFT API: Moralis’ NFT API is perfect for creating NFT marketplaces, Web3 games, or any other NFT-based platforms. With single lines of code, you can access NFT balances, metadata, prices, and more using the NFT API.
Text: "NFT API"

Please visit the official Web3 API page for an in-depth look at these interfaces and to learn more about our other APIs!

Summary: Streams Vs. Ethers.js – The Best Way to Get Real-Time Web3 Data

One way to get real-time Web3 data is to leverage Ethers.js, a well-known JavaScript library for building dapps. However, monitoring blockchain events with Ethers.js can be complicated, time-consuming, and expensive. Fortunately, there’s a better alternative: Moralis’ Streams API!

The Streams API simplifies the process of fetching real-time Web3 data. With its intuitive point-and-click interface, you can easily set up streams to monitor events for any wallet, address, or asset on any chain without breaking a sweat! 

But what makes the Streams API a superior choice compared to Ethers.js for querying real-time Web3 data?

Here’s a quick comparison of the two:

If you found this guide on Ethers.js and Streams helpful, consider exploring more content on our blog. For instance, check out our recent articles on:

Additionally, if you want to use the Streams API yourself, be sure to register for an account with Moralis. You can sign up for free and gain instant access to our industry-leading development tools!

Streams API
Stream Web3 events and get real-time notifications whenever something important happens on-chain!
Streams API
Related Articles
December 29, 2022

How Developers Can Add Blockchain-Based Data Storage Into Web3 Projects

January 22, 2024

Full Guide – The Ethereum Ecosystem in 2024

January 6, 2023

Smart Contract Programming Tutorial for Blockchain Developers

September 22, 2022

How to Build a Web3 FIFA Clone

December 2, 2022

Full Guide: What is Ethers.js?

January 30, 2023

OpenZeppelin in Remix – Importing OpenZeppelin Contracts in Remix

March 4, 2023

Solana Devnet – How to Build Dapps on Solana

December 9, 2022

How to Listen to the Blockchain with Ethers.js

January 3, 2023

Web3.py vs Web3.js – Ultimate Comparison of Two Leading Web3 Libraries

🔥 LIMITED-TIME OFFER - Get early access to an Enhanced Token Page & boost your token project’s exposure! GET EARLY ACCESS 🔥