Search code examples
javascriptblockchainethereumetherscan

Is possible to see output data when tracking a transaction from its address on Etherscan?


I wonder if it is possible to see "Output Data" on Etherscan for non-view transactions that returned values, I mean it is possible to see "Input Data" when fetching a transaction on Etherscan from its address but can I find transaction's output data?


Solution

  • Not possible by design. Returned values from functions invoked by a transaction are not available outside of EVM message calls (aka internal transactions).

    You can either emit an event or create a getter function to retrieve the value.

    pragma solidity ^0.8;
    
    contract MyContract {
        uint256 number;
        event NumberChanged(uint256);
    
        function setNumber(uint256 _number) public returns (uint256) {
            number = _number;
    
            // available outside of EVM, n/a for internal transactions
            emit NumberChanged(_number);
    
            // available for internal transactions inside EVM, n/a outside
            return _number;
        }
    
        // available for both internal transactions and outside of EVM
        function getNumber() public view returns (uint256) {
            return number;
        }
    }