0

Help me please . if we will using : await provider.getTransaction('0xeed4fadf09e9560f01056f240f86b515dce717087a42c7266bf659edef555861') ---> in this case i will have result for only this hash .

But i need to get hash with dynamic users for any transactions like : const tx = provider.getTransaction(anyTransactionHash) ;

so How can get anyTransactionHash ? Thanks

1
  • Hello. I do not understand what you are asking for. Commented Jul 1, 2022 at 6:06

1 Answer 1

0

Probably what you want is to monitor pending transactions? If that's the case, you need to connect to a node via websocket and subscribe to the "PendingTransactions". Something like this:

var Web3 = require('web3')

const main = async () => {
  // reconnect options
  const options = {
    reconnect: {
      auto: true,
      delay: 2000,
      maxAttempts: 3,
      onTimeout: false,
    },
  }
  const web3 = new Web3(
    new Web3.providers.WebsocketProvider('wss://your-node-endpoint/12345',
      options
    )
  )

  // subscribe to pendingTransactions events
  web3.eth
    .subscribe('pendingTransactions', async (error, result) => {
      if (error) console.log('error', error)
    })
    .on('data', async (trxId) => {
      // receives the transaction id
      console.log('TRX ID >> ', trxId)
      // query all transaction details using its id
      const trxDetails = await web3.eth.getTransaction(trxId)
      console.log(`TRX ${trxId} DETAILS >> `, trxDetails)
    })
}

main()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.