Alchemy Launches Filtered Pending Transaction Notifications
For the first time, developers can see real-time engagements with their smart contracts and end-users can get real time updates over their transaction lifecycle.
Let’s say you are a smart contract owner and you want to see all pending transactions for your contract. Maybe you’re building out health monitoring for your contract. Maybe you’re trying to route pending notifications to your users. Regardless, it’s a big hassle to do this in the ecosystem today.
Streaming your contract transactions without Alchemy
Let’s first take a look at how you would do this without Alchemy. Ethereum exposes the eth_newPendingTransactions API, which will give you a stream of pending transaction hashes. Then for each of these transaction hashes you can fetch the full transaction payload, extract the contract address, and then run your business logic if the address matches your contract.
This process gets expensive very quickly as you will be checking dozens of transactions per second, most of which are irrelevant to you, and making a network call for each one of them.
Introducing Alchemy's filtered transactions API
Rather than accepting a full stream of pending transaction hashes and then checking each one, Alchemy will run the check for you before streaming. You provide an address to our alchemy_pendingTransactions endpoint and we will stream you pending transactions that are going to or from the address.
Let’s see this in action. We’ll observe pending transactions for SushiSwap's router address.
As you can see SushiSwap is pretty active.
What can we build with this?
We're excited to see what you come up with! To get your creative juices flowing, here are some applications that are now massively easier to build:
Create an activity monitor on your smart contract. You can set up a subscription to stream pending transactions to your smart contract. If you don't receive a transaction within a given time frame, fire off an alert!
Find out when a particular address becomes "active". Maybe you want to know when someone sends ETH to a verified scam address. Or when a black hat hacker finally removes funds from a particular address.
Notify your end users when their transaction is pending. Set up a subscription from the client side when your end-user submits a transaction, and notify your user when the transaction is submitted to the mempool. Perhaps soon we won't have to keep reloading block explorers?
For other subscription capabilities as well as webhooks, check out Alchemy’s Notify offering.
Related articles
Deeper application insights at lower costs
By re-architecting back end infrastructure, Alchemy has passed up to 3x efficiency savings to you for four key debug_trace methods.
The Graph's Hosted Service is Shutting Down - Migrate Now
Migrate your hosted subgraph from The Graph to Alchemy by June 12th and get personalized migration assistance.
Polygon Mumbai Support Ending April 13th - Migrate to Amoy
Polygon will deprecate the Mumbai testnet on April 13th, 2024. We encourage developers to migrate to Polygon Amoy immediately.