function_selector_json

Builds the canonical signature for a JSON ABI function fragment and returns its 4-byte Keccak-256 selector.

Example

Local

1
SELECT function_selector_json(json('{
2
"type": "function",
3
"name": "transfer",
4
"inputs": [
5
{"name": "to", "type": "address"},
6
{"name": "value", "type": "uint256"}
7
]
8
}')) AS selector;
Notebook ready in readonly mode.

API reference

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

function_selector_json(JSON) #

Canonicalizes one JSON ABI function fragment, then hashes the derived signature.

Inputs

Name Type Use
abi JSON

A single function ABI object with name and inputs. Tuple and array structure is preserved while uint/int aliases are normalized to uint256/int256.

required positional

Returns

Name Type
selector BYTES4

Function selector. Returns the first four bytes of Keccak-256 over the canonical function signature as BYTES4.

Guidance

Choose a selector source

Use function_selector_json when the source of truth is a JSON ABI fragment. It preserves tuple and array structure and normalizes uint and int aliases before hashing.

  • Use function_selector for signature text that is already canonical.
  • Use encode_function_data when complete selector-prefixed calldata is required.
  • Use event_signature for event topic0.

Local SQL

1
SELECT function_selector('transfer(address,uint256)') AS selector;
Notebook ready in readonly mode.

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