function_selector

Returns the 4-byte Keccak-256 selector for an already-canonical function signature. The input bytes are hashed exactly and are not normalized.

Example

Local

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

API reference

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

function_selector(VARCHAR) #

Hashes one already-canonical function signature without normalization.

Inputs

Name Type Use
signature VARCHAR

Signature text such as transfer(address,uint256), without parameter names or return types. The bytes are hashed exactly; no whitespace or type alias normalization is performed.

required positional

Returns

Name Type
selector BYTES4

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

Guidance

Supply canonical signature text

The function hashes the supplied bytes exactly. Whitespace, parameter names, return types, and aliases such as uint change the hash instead of being normalized.

  • Use text such as transfer(address,uint256).
  • Use function_selector_json when canonicalization should be derived from a JSON ABI.
  • Use encode_function_data when complete selector-prefixed calldata is required.

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