Skip to main content

decodeFunctionCall

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
    const data =
    '0xa413686200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010416e6f74686572204772656574696e6700000000000000000000000000000000';
    const params = decodeFunctionCall(
    {
    inputs: [
    { internalType: 'string', name: '_greeting', type: 'string' },
    { internalType: 'string', name: '_second_greeting', type: 'string' },
    ],
    name: 'setGreeting',
    outputs: [
    { internalType: 'bool', name: '', type: 'bool' },
    { internalType: 'string', name: '', type: 'string' },
    ],
    stateMutability: 'nonpayable',
    type: 'function',
    },
    data,
    );

    console.log(params);
    > {
    > '0': 'Hello',
    > '1': 'Another Greeting',
    > __length__: 2,
    > __method__: 'setGreeting(string,string)',
    > _greeting: 'Hello',
    > _second_greeting: 'Another Greeting',
    > }

    Parameters

    • functionsAbi: AbiFunctionFragment | AbiConstructorFragment

      The JSON interface object of the function.

    • data: string

      The data to decode

    • methodSignatureProvided: boolean = true

      (Optional) if false do not remove the first 4 bytes that would rather contain the function signature.

    Returns DecodedParams & { __method__: string }

    • The data decoded according to the passed ABI.