Solidity – How to Get Status of a Transaction Within the Contract

ethersolidity

Is it possible to get the status of a Transaction like if it went thru fine or any failure, within a smart contract function itself. lets say, I am trying to transfer some ether to a different address and want to know if the Tx succeeded.

  address payable to = external_address;
            uint256 amount = _amount;
            to.transfer(amount); 
            //wait for the Tx to complete, then update the status as done

Is there a way to know if the transfer went thru fine?

Thanks

Best Answer

First, EVM/Solidity doesn’t have the concept of a transaction hash. That’s the blockchain/record part.

In your case, there’s no need for you to check if the transfer went through. The transfer REVERTS if failed. And any revert bubbles up so the function itself reverts and the user can then see this in their transaction hash.

Related Topic