2

How do I encode data for inner transaction call of ERC223Receiver contract after transferring erc223 tokens to it?

example:

Contract ERC223Receiver {
    function foo(uint256 a) {
        // some work
    }
}


Contract Other {
    function bar(address token, address receiver, uint256 amount, uint256 a) {
        bytes4 sig = bytes4(sha3("foo(uint256)"));

        bytes data = bytes(sig + a) // ????

        token.transfer(receiver, amount, data);
    }
}
1
  • The scenario you are describing is closer to ERC827, not ERC223. ERC223 expects 'tokenFallback' function on the receiving end, and calls it passing the argument data, no need to package the function signature itself
    – Andrey
    Jun 18 '18 at 16:16
0

I managed to figure it out using assembly:

Contract Other {
    function bar(address token, address receiver, uint256 amount, uint256 a) {
        bytes4 sig = bytes4(sha3("foo(uint256)"));
        uint256 argsSize = 1 * 32;
        // sig + arguments size
        uint256 dataSize = 4 + argsSize;

        bytes memory m_data = new bytes(dataSize);

        assembly {
            // Add the signature first to memory
            mstore(add(m_data, 0x20), sig)
            // Add the parameters
            mstore(add(m_data, 0x24), a)
        }

        token.transfer(receiver, amount, m_data);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.