encode_function_data
Scalar function
Encodes contract function arguments using ABI definitions, returning selector-prefixed calldata.
encode_function_data(JSON, VARCHAR, ABI-dependent argument(s))
Matches the requested function within the provided ABI (including overloads) and ABI-encodes the variadic arguments.
Parameters
| Name | Type |
|---|---|
| abi | JSON |
| function_name | VARCHAR |
| ... | ABI-dependent argument(s) |
Returns
| Name | Type |
|---|---|
| calldata | BLOB |
1
-- Encode balanceOf(address) calldata for Vitalik's address
2
WITH abi AS (
3
SELECT '[
4
{
5
"type": "function",
6
"name": "balanceOf",
7
"stateMutability": "view",
8
"inputs": [{ "name": "account", "type": "address" }]
9
}
10
]'::JSON AS abi_json
11
)
12
SELECT encode_function_data(abi.abi_json, 'balanceOf', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS)
13
FROM abi;
Notebook ready in readonly mode.