Skip to main content

encodeFunctionSignature

Callable


  • Encodes the function name to its ABI representation, which are the first 4 bytes of the sha3 of the function name including types. The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json

    @example
    const signature = web3.eth.abi.encodeFunctionSignature({
    name: "myMethod",
    type: "function",
    inputs: [
    {
    type: "uint256",
    name: "myNumber",
    },
    {
    type: "string",
    name: "myString",
    },
    ],
    });
    console.log(signature);
    > 0x24ee0097

    const signature = web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
    console.log(signature);
    > 0x24ee0097

    const signature = web3.eth.abi.encodeFunctionSignature('safeTransferFrom(address,address,uint256,bytes)');
    console.log(signature);
    > 0xb88d4fde

    Parameters

    • functionName: string | AbiFunctionFragment

      The function name to encode or the JSON interface object of the function. If the passed parameter is a string, it has to be in the form of functionName(param1Type,param2Type,...). eg: myFunction(uint256,uint32[],bytes10,bytes)

    Returns string

    • The ABI signature of the function.