If I send a transaction, I can watch the result using window.web3.eth.getTransactionReceipt like this:

  from: pubData.user.address,
  gas: gasAmount
  .then(res => {
    let txId = res.transactionHash
    let isSuccess
    window.web3.eth.getTransactionReceipt(txId).then(transReceipt => {
      if (transReceipt) {
        isSuccess = transReceipt.status === '0x1'
        if (isSuccess) {
         // do something if transactions success
        } else {
       // do something if transactions fail

However, if I listen to the Transfer event of the contract

listenContract.events.Transfer({}, (er, data) => {
  let txId = data.transactionHash
  window.web3.eth.getTransactionReceipt(txId).then(transReceipt => {
    // always return null because the transaction is pending
    console.log('transReceipt', transReceipt)

transReceipt is always null because the transaction is pending. So, in this case, do we have to poll until the transaction finish? Does web3.js has some API can do it like the code on top? I didn't find it. I do find a lot of poll solution like:

Get Transaction Hash And Mined Receipt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.