encode_function_args

Encodes function arguments with standard ABI encoding and omits the 4-byte function selector.

Example

Local

1
-- Encode transfer(address,uint256) arguments without the selector
2
WITH abi AS (
3
SELECT '[{
4
"type": "function",
5
"name": "transfer",
6
"inputs": [
7
{ "name": "to", "type": "address" },
8
{ "name": "value", "type": "uint256" }
9
]
10
}]'::JSON AS abi_json
11
)
12
SELECT encode_function_args(
13
abi.abi_json,
14
'transfer(address,uint256)',
15
'0x000000000000000000000000000000000000dEaD'::ADDRESS,
16
parse_units('2500', 6)
17
) AS encoded_args
18
FROM abi;
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

encode_function_args(JSON, VARCHAR, ...args) #

Uses the same function selection and value coercion rules as encode_function_data, but returns only standard ABI argument bytes.

Note: A single function-selector literal is not validated.

Inputs

Name Type Use
abi JSON

Contract ABI JSON containing the target function.

required positional
function_name VARCHAR

Function name, canonical signature, or 4-byte selector literal. Use a canonical signature when the ABI contains overloaded functions.

required positional
...args dynamic ANY

One SQL value per selected function input, in ABI order. The ABI determines each accepted SQL cast and the encoded Solidity type.

positional

Returns

Name Type
encoded_args BYTES

Selector-free ABI arguments. Returns BYTES containing only the ABI-encoded function arguments, without the 4-byte selector.

Guidance

Build nested ABI payloads

Use encode_function_args when a protocol expects ABI-encoded function arguments nested inside another payload, or when reproducing Solidity abi.encode(...) output.

  • Use encode_function_data for top-level contract calldata.
  • Use the canonical signature when an ABI has overloaded functions.
  • The ABI and argument coercion rules match encode_function_data.

Local SQL

1
WITH abi AS (
2
SELECT '[{
3
"type": "function",
4
"name": "transfer",
5
"inputs": [
6
{ "name": "to", "type": "address" },
7
{ "name": "value", "type": "uint256" }
8
]
9
}]'::JSON AS abi_json
10
)
11
SELECT encode_function_args(
12
abi_json,
13
'transfer(address,uint256)',
14
'0x000000000000000000000000000000000000dEaD'::ADDRESS,
15
parse_units('2500', 6)
16
) AS encoded_args
17
FROM abi;
Notebook ready in readonly mode.

Selector literals

A selector literal can select the only function in a single-function ABI, but the current implementation does not compare that literal with the function's derived selector.

Use a function name or canonical signature when selector validation is required.

Choose the right ABI primitive

Choose by byte framing and direction: selector construction, standard arguments, calldata, packed bytes, raw words, calldata decoding, and return-data decoding are distinct operations.

  • function_selector hashes already-canonical signature text exactly; function_selector_json builds a canonical signature from one JSON ABI fragment first.
  • encode_function_args emits selector-free standard ABI arguments; encode_function_data prefixes those same bytes with the 4-byte selector.
  • abi_encode_packed concatenates compact scalar encodings without standard ABI offsets, lengths, or 32-byte padding; evm_abi_word always emits exactly one padded 32-byte word.
  • decode_function_data consumes and validates selector-prefixed calldata inputs; call_decode consumes selector-free function return bytes.

Local SQL

1
SELECT
2
function_selector('transfer(address,uint256)') AS selector,
3
encode_function_data(
4
'[{"type":"function","name":"transfer","inputs":[{"type":"address"},{"type":"uint256"}]}]'::JSON,
5
'transfer(address,uint256)',
6
'0x000000000000000000000000000000000000dEaD'::ADDRESS,
7
1::UINT256
8
) AS calldata;
Notebook ready in readonly mode.

Related functions

Category and tags

Tag
ABI