Skip to main content

decodeFunctionReturn

Callable


  • Decodes a function call data using its JSON interface object. The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json

    @example
    // decode a multi-value data of a method
    const data =
    '0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000';
    const decodedResult = decodeFunctionReturn(
    {
    inputs: [
    { internalType: 'string', name: '_greeting', type: 'string' }
    ],
    name: 'setGreeting',
    outputs: [
    { internalType: 'string', name: '', type: 'string' },
    { internalType: 'bool', name: '', type: 'bool' },
    ],
    stateMutability: 'nonpayable',
    type: 'function',
    },
    data,
    );

    console.log(decodedResult);
    > { '0': 'Hello', '1': true, __length__: 2 }


    // decode a single-value data of a method
    const data =
    '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000';
    const decodedResult = decodeFunctionReturn(
    {
    inputs: [
    { internalType: 'string', name: '_greeting', type: 'string' }
    ],
    name: 'setGreeting',
    outputs: [{ internalType: 'string', name: '', type: 'string' }],
    stateMutability: 'nonpayable',
    type: 'function',
    },
    data,
    );

    console.log(decodedResult);
    > 'Hello'

    Parameters

    • functionsAbi: AbiFunctionFragment

      The JSON interface object of the function.

    • optionalreturnValues: string

      The data (the function-returned-values) to decoded

    Returns unknown

    • The ABI encoded function call, which, means the function signature and the parameters passed.