[Ethereum] Monitoring Pending Transactions

pending-transactionstransactions

How would I go about monitoring pending transactions in real-time? Would I be able to monitor only one function?

I have a full node running and have a nodejs (express server) that I want to have this info available to.

I am guessing that a websocket would be the way to go, in which case what would I be listening for?

Best Answer

  1. You can create a stream of pending transactions using web3.eth.subscribe('pendingTransactions' [, callback]);, which currently returns a transaction hash.
  2. You can turn into the actual transaction object using web3.eth.getTransaction(transactionHash [, callback]), which will return a transaction object.
  3. You can then filter the returned object by to and input to find only the transactions that are being sent to a specific contract address and are calling a specific function in that contract.
Related Topic