Ethers vs Webhooks
Reacting to real-time events from Avalanche smart contracts allows for immediate responses and automation, improving user experience and streamlining application functionality. It ensures that applications stay synchronized with the blockchain state.
This article demonstrates how to monitor smart contract events using Ethers.js and Avacloud Webhooks. The comparison shows that Avacloud webhooks are easier and faster to integrate, delivering better uptime and reliability.
Why webhooks
- Get everything you need in the payload, there is no need for extra requests
- There is no complicated logic to handle disconnections and to re-sync and recover missed blocks or transactions.
- Reduce complexity, cost, and time to market.
Ethers.js Blockchain Listener
Output
Get undecoded raw data and then you need to call other API endpoints to get more data, for example, to get the current balance you need to make an API call, to get the token decimals you need to make an API call, to get the logo you need to make an API, you get it.
They provide real-time updates, reduce resource use, and enhance efficiency, allowing users to focus on building around these events rather than parsing data.
Listening to the same contract using AvaCloud Webhooks
Listening to native transactions
To monitor native transactions for specific addresses in an Ethereum blockchain, you need to follow these steps:
- Listen for Every New Block: Set up a listener for new blocks.
- Go Through All Transactions in Each Block: For each block, iterate through all transactions.
- Check If from or to Matches Your List of Addresses: Filter the transactions to see if either the sender (from) or the recipient (to) matches your list of addresses.
- Handle Transactions: Implement logic to handle the transactions that match your criteria.
How Avacloud webhooks are better Than Ethers.js
Ethers.js is a good alternative for setting blockchain listeners to monitor smart contract events. However, if you start working with this library, you will quickly notice its limitations.
Feature | Ethers/web3.js | Webhooks |
---|---|---|
Real-time events | Yes | Yes |
Enriched payload | No | Yes |
100% reliability | No | Yes |
Multiple addresses | No | Yes |
Listen to wallet addresses | No | Yes |
Resume capabilities
Ethers.js does not natively support resuming operations if the connection is interrupted. When this happens, the blockchain continues to add new blocks, and any blocks that were added during the downtime can be missed. To address this, developers must implement custom code to track the last processed block and manually resume from that point to ensure no data is lost.
In contrast, Webhooks are designed to handle interruptions more gracefully. They typically have built-in mechanisms to ensure that events are not lost, even if the connection is disrupted. When the connection is restored, Webhooks can automatically resume from where they left off, ensuring that no events are missed without requiring additional custom code. This makes Webhooks a more reliable solution for continuous data processing and real-time event handling.
Was this page helpful?