I'd want to have:

  1. original types
  2. --> encode them in bytes
  3. --> string those bytes all together or as an array [[address, address], [uint, uint], [other_type, other_type],...]
  4. --> convert to hex
  5. --> call smart contract

In the contract's called function - I'd then:

  1. --> decode from hex to bytes
  2. --> split the bytes accordingly to user's intent, then convert them to original types

Is that possible at all? The calldata's length's not fixed, but dynamic. I can see two approaches:

a) Can calldata be decoded from hex to bytes then split:

  • calldata as hex -> calldata as bytes
  • calldata[0] would then be eg. address[] type as bytes,
  • calldata[1] could be other types and so on

b) if not, can I just mash all the bytes of different types together, convert it to hex, and then decode them simply by index in smart contract?

Not sure how to test that myself, I'm getting some strange results at the first small steps: [Remix IDE]

contract test {
    function foo(bytes calldata _data) external view returns (uint256) {
        uint256 x = uint256(bytes32(_data));
        return x;

When called with 0x05 result is:

    uint256: 2261564242916331941866620800950935700259179388000792266395655937654553313280

I've checked out various calculators and converters on the web and they seem to differ from this or one another (don't know enough, but I'm pretty sure 0x05 is not that thing above?).

  • Encoding bytes as hexadecimal is done at the RPC level, at the blokchain level the contract receives a raw sequence of bytes, you don't need to hex-decode them. To decode a bytes use abi.decode.
    – Ismael
    Commented Aug 6, 2022 at 17:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.