0

I have a function which writes into the blockchain. I would like to know if the transaction which calls the function has been succcessful or not. So far I did this with the tx receipt, but that takes multiple seconds to get. I don't need the tx receipt for further processing, therefore I am wondering if it is possible to figure out (hopefully faster) if the tx was successful or not. My first idea is that it can be simply done with a return value from the function. So my question is that when will my web3 client receive the return value of the fooFunction? I assume when the block/tx was validated. Or can I get back the currentBalance return value from the function while the tx will fail? Or if my client gets the proper return value that means the tx has been executed properly?

function fooFunction (address addr, address rec) external return (uint256) {
    IBEP20 tokenContractObject = IBEP20(addr);
    uint256 currentBalance = tokenContractObject.balanceOf(address(this));
    // do some work with the balance
    return currentBalance
  }

1 Answer 1

0

when will my web3 client receive the return value of the fooFunction?

If the transaction is successful. Also, not all functions that write to the blockchain require a return value.

Or can I get back the currentBalance return value from the function while the tx will fail?

No, if the transaction fails, it will revert with an error message.

Or if my client gets the proper return value that means the tx has been executed properly

Not necessarily, sometimes a transaction can go smoothly on the client side but an error occurs on the server side. I would say if a transaction goes smoothly on both the client and server side, it's considered been executed properly.

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.