# to_hex

Formats a BLOB-backed EVM byte value as uppercase hexadecimal text without a 0x prefix. hex and to_hex are compatibility aliases with identical behavior.

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

- Kind: scalar function
- Category: [EVM utilities](/docs/category/evm-utilities.md)
- Tags: Bytes, Hex, EVM, Deterministic, Types

Formats a BLOB-backed EVM byte value as uppercase hexadecimal text without a 0x prefix. hex and to_hex are compatibility aliases with identical behavior.

## Overload 1: to_hex(ADDRESS)

```sql
to_hex(ADDRESS)
```

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- 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

- `value` (ADDRESS; required; positional) — ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

### Returns

Uppercase hexadecimal text

Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

- `hex` (VARCHAR)

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

## Overload 2: to_hex(BYTES4)

```sql
to_hex(BYTES4)
```

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- 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

- `value` (BYTES4; required; positional) — ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

### Returns

Uppercase hexadecimal text

Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

- `hex` (VARCHAR)

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

## Overload 3: to_hex(BYTES32)

```sql
to_hex(BYTES32)
```

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- 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

- `value` (BYTES32; required; positional) — ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

### Returns

Uppercase hexadecimal text

Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

- `hex` (VARCHAR)

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

## Overload 4: to_hex(BYTES256)

```sql
to_hex(BYTES256)
```

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- 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

- `value` (BYTES256; required; positional) — ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

### Returns

Uppercase hexadecimal text

Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

- `hex` (VARCHAR)

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

## Additional examples

```sql
-- to_hex is the compatibility alias of hex
SELECT to_hex('0xa9059cbb'::BYTES4) AS selector_hex;
-- => [{"selector_hex":"A9059CBB"}]
```
