Skip to content

encodeFunctionData

encodeFunctionData(abi, functionName, args): string

Defined in: utils/abi-encode-decode.ts:46

Encode function call data from a full ABI, function name, and arguments.

Parameters

abi

JSONABI

The full JSON ABI array of the contract

functionName

string

The name of the function to encode

args

any[] = []

The arguments to pass to the function

Returns

string

The ABI-encoded hex string (with 0x prefix and 4-byte selector)

Example

import { encodeFunctionData } from 'essential-eth';
const abi = [
{
name: 'balanceOf',
type: 'function',
inputs: [{ name: 'owner', type: 'address' }],
outputs: [{ name: 'balance', type: 'uint256' }],
},
];
const data = encodeFunctionData(abi, 'balanceOf', [
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
]);