Skip to main content

encodeFunctionCall

Callable


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

    @example
    const sig = web3.eth.abi.encodeFunctionCall(
    {
    name: "myMethod",
    type: "function",
    inputs: [
    {
    type: "uint256",
    name: "myNumber",
    },
    {
    type: "string",
    name: "myString",
    },
    ],
    },
    ["2345675643", "Hello!%"]
    );
    console.log(sig);
    > 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000



    const sig = web3.eth.abi.encodeFunctionCall(
    {
    inputs: [
    {
    name: "account",
    type: "address",
    },
    ],
    name: "balanceOf",
    outputs: [
    {
    name: "",
    type: "uint256",
    },
    ],
    stateMutability: "view",
    type: "function",
    },
    ["0x1234567890123456789012345678901234567890"]
    );

    console.log(sig);
    > 0x70a082310000000000000000000000001234567890123456789012345678901234567890

    Parameters

    • jsonInterface: AbiFunctionFragment

      The JSON interface object of the function.

    • params: unknown[]

      The parameters to encode

    Returns string

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