Skip to main content

inferTypesAndEncodeParameters

Callable

  • inferTypesAndEncodeParameters(params: unknown[]): string

  • Infer a smart contract method parameter type and then encode this parameter.

    @remarks

    This method is useful when you don't know the type of the parameters you want to encode. It will infer the type of the parameters and then encode them. However, it is not recommended to use this method when you know the type of the parameters you want to encode. In this case, use the encodeParameters method instead. The type inference is not perfect and can lead to unexpected results. Especially when you want to encode an array, uint that is not uint256 or bytes....

    @example
    const res = web3.eth.abi.encodeParameters(
    ["2345675643", "Hello!%"]
    );

    console.log(res);
    > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000

    Parameters

    • params: unknown[]

      The parameters to encode.

    Returns string

    • The ABI encoded parameters