0

I'm trying to understand how errors are handled by Web3's Callback Promises Events. Below is the PromiEvents definition as given on https://web3js.readthedocs.io/en/v1.4.0/callbacks-promises-events.html

web3.eth.sendTransaction({from: '0x123...', data: '0x432...'})
.once('sending', function(payload){ ... })
.once('sent', function(payload){ ... })
.once('transactionHash', function(hash){ ... })
.once('receipt', function(receipt){ ... })
.on('confirmation', function(confNumber, receipt, latestBlockHash){ ... })
.on('error', function(error){ ... })
.then(function(receipt){
    // will be fired once the receipt is mined
});

I wrapped the above with few more lines of codes in try-catch block and made a deliberate error by using transferFrom function without setting any allowance for the transaction.

I expected the error:

Returned error: execution reverted: ERC20: transfer amount exceeds allowance

to be handled by "error" listener present in the chain. But the error was handled by 'catch' of try-catch block.

Then I added a 'catch' method in the chain. Still the error was handled by try-catch.

Questions:

  1. So the first question is: what is the code execution flow in terms of stages in Ethereum blockchain?
  2. Second question is: At which stage, the event object create, is destroyed?

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.