# 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.

Canonical HTML: <https://determica.com/docs/functions/function_selector>

- Kind: scalar function
- Category: [Contracts and ABI](/docs/category/contracts-and-abi.md)
- Tags: ABI

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

## Overload 1: function_selector(VARCHAR)

```sql
function_selector(VARCHAR)
```

Hashes one already-canonical function signature without normalization.

- Kind: scalar
- Execution context: Offline
- Behavior: Exact Signature Function Selector
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `signature` (VARCHAR; required; positional) — 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.

### Returns

Function selector

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

- `selector` (BYTES4)

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

### Examples

_Local SQL · Local_

```sql
SELECT function_selector('transfer(address,uint256)') AS selector;
```

## 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.

### 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.

```sql
SELECT
  function_selector('transfer(address,uint256)') AS selector,
  encode_function_data(
    '[{"type":"function","name":"transfer","inputs":[{"type":"address"},{"type":"uint256"}]}]'::JSON,
    'transfer(address,uint256)',
    '0x000000000000000000000000000000000000dEaD'::ADDRESS,
    1::UINT256
  ) AS calldata;
```

## Related functions

- [function_selector_json](/docs/functions/function_selector_json.md) — Alternative
- [encode_function_data](/docs/functions/encode_function_data.md) — See Also
- [encode_function_args](/docs/functions/encode_function_args.md) — See Also
- [raw_call](/docs/functions/raw_call.md) — Usually Before
