0

Commonly, I dow

const receipt = await web3.eth.sendSignedTransaction(web3, signed_transaction);
console.log("tx_hash:", receipt.transactionHash);
console.log("gas_used:", receipt.gasUsed);
console.log("gas_price:", offered_gas_price);

But I do not want (no more) to get the return output, because it's too slow.

So I started a nodejs server to listen to contract events, and it works.

No, how can I call web3.eth.ssendSignedTransaction without wait for result?

I simply tried to call

web3.eth.sendSignedTransaction(web3, signed_transaction);

But I discovered that nothing is happening at all against my contract.

Should be a js problem only. But, in case no, can I simply send a transaction and ignore esit?

how?

1
  • You should be able to send a transaction without waiting for confirmations. I'd check if the transaction status, if it is in the pending pool, or it was mined and it failed.
    – Ismael
    Apr 8, 2020 at 20:20

1 Answer 1

2

You should be able to send a transaction without waiting for confirmations. I'd check if the transaction status, if it is in the pending pool, or it was mined and it failed.

With web3 1.2 you can listen for the transactionHash and query for the transaction details. See the documentation https://web3js.readthedocs.io/en/v1.2.6/callbacks-promises-events.html#promievent

web3.eth.sendSignedTransaction('0x...')
  .once('transactionHash', function(hash){
    web3.eth.getTransactionReceipt(hash).then(() => {
    ..
  })
})

To wait for the hash you might wrap the call in a promise

function waitForHash(signedTx) {
  return new Promise((resolve, reject) => {
    web3.eth.sendSignedTransaction(signedTx)
      .once('transactionHash', (hash) => {
        resolve(hash)
    })
  })
}

Now you can call it like this:

const hash = await waitForHash('0x....')
3
  • Thanks. Do you know how can we stop js just untile the once is executed? using await it waits for then, and it's too long to leave js pending in my specific case. How can I wait only for this event?
    – realtebo
    Apr 9, 2020 at 7:59
  • 1
    @realtebo I edited my question to show one possible method to wait for hash. I don't know if it will work in your case because you need to wait until the transaction has been sent.
    – Ismael
    Apr 9, 2020 at 22:02
  • Thanks again. I ended just waiting for the hash, and the a parallele job query contract events to get results. You mada me discovere the PromiEvent I didn't know before.
    – realtebo
    Apr 10, 2020 at 8:00

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.