flutterisbae
flutterisbae

Reputation: 345

Monitoring Polygon wallet transactions with c#

I'm new to blockchain development. I have a requirement where for one hour, I need to monitor an Eth address and detect any transactions, upon which I will do some logic.

The simplest way is to brute force it, like for every minute, get the transactions for this address and see the difference. But for hundreds of addresses at once this is a very bad idea.

I've been looking for a more elegant way of handling this. I've looked into web hooks, subscriptions, web sockets, but can't find anything that includes Polygon Mainnet and Mumbai.

This monitoring service would need to be able to interact with a database. The idea is that for one hour, we monitor an address, we see a new transaction, and we send something to the database and stop the monitoring. What could be a solution for this?

Thanks.

Upvotes: 0

Views: 953

Answers (2)

flutterisbae
flutterisbae

Reputation: 345

I ended up using Nethereum's API for this. I set up a Web3, an EventDTO to model the Smart Contract function that I was trying to track, and a FilterInput just for the address I was concerned about. I used a StreamingWebSocketClient with a public web socket URL for Matic Testnet, and from there I just tracked the logs with a EthLogsObservableSubscription, decoding the event into my EventDTO.

Upvotes: 1

mnkhod
mnkhod

Reputation: 79

Seems like the most performant way of solving this would be having a listener on your polygon node. I suggest going with alchemy and using ethers js to listen on new blocks.

https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/

  • here on the ethers js doc you can listen for events after connecting the ethers js provider with ur alchemy node.

https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/-%23-Provider--events

  • over on this section of the doc you can find event names and the event name that would solve your case would be "block"
provider.on("block",(blocknumber) => {
 // this function would work every time a new block is mined
});

Upvotes: 1

Related Questions