[Ethereum] get the return value of a .call from a contract from the Blockchain

eth-callsolidityweb3js

I know that if I use call from a contract, that I cannot get the return value. I get a true or a false.

Is it possible for me to inspect the blockchain afterwords to get the return value?

For example, if the function that I CALL creates an new contract and returns the address, can I endow the the mined block and find the address of the created contract?

What if it returned a uint?

How would I do this? Web3?

I've created a blog post that shows a bit of what I'm trying to accomplish here: http://catallax.info/news/2017/6/8/calling-future-contracts-from-contracts-in-ethereum-dev-log-6

Best Answer

Low-level calls are just a tiny bit above inline assembly, so you can use inline assembly to emulate this feature.

Something like this:

function get(address _addr, string _func) public view returns (bytes data) {
    uint len = 32;
    uint ptr;

    bytes4 sig = bytes4(keccak256(_func));
    assembly {
        ptr := mload(0x40)       
        mstore(ptr, sig)

        let result := call(5000, _addr, 0, ptr, 0x4, ptr, add(len, 0x40))

        if eq(result, 0) {
            revert(0, 0)
        }

        ptr := add(ptr, 0x40)
        mstore(0x40, add(ptr, add(len, 0x40)))
    }

    data = toBytes(ptr, len); 
}

function toBytes(uint _addr, uint _len) internal pure returns (bytes memory bts) {
    bts = new bytes(_len);
    uint btsptr;
    assembly {
        btsptr := add(bts, 0x20)
    }
    copy(_addr, btsptr, _len);
}
Related Topic