dapptools icon indicating copy to clipboard operation
dapptools copied to clipboard

support tuples in abi encoding

Open MrChico opened this issue 4 years ago • 2 comments

pragma experimental "ABIEncoderV2";

contract A {
    struct A {
        uint x;
        uint y;
    }
    function test_A(A calldata a) external {
    }
}

MrChico avatar Feb 25 '21 09:02 MrChico

There is a workaround: structs are abiencoded as their components, so for example a function:

pragma experimental "ABIEncoderV2";

contract A {
    struct A {
        uint x;
        uint y;
    }
    function test_A(A calldata a) external {
    }
}

the function signature for test_A is 0x772d5055: test_A((uint256,uint256)) aka seth sig "test_A((uint256,uint256)). However, if you do seth calldata "test_A((uint256,uint256))" 1 2 you will run into problems in parsing the extra parens (it's not valid solidity syntax). But the encoding of the arguments is the same, only the function signature differs. So you can cut in the correct function signature but use the normal way of encoding the arguments:

echo $(seth sig "test_A((uint256,uint256)")$(seth calldata "test_A(uint256,uint256)" 1 2 | cut -c 11-)

MrChico avatar Feb 25 '21 09:02 MrChico

It seems there is a typo on the suggestion above - one extra "(" in front of test_A. So I think the intention was the following:

echo $(seth sign "test_A(uint256,uint256)")$(seth calldata "test_A(uint256,uint256)" 1 2 | cut -c 11-)

tfalencar avatar Mar 22 '22 15:03 tfalencar