> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Uint.toHex

> Convert Uint256 to hex string with 0x prefix

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/uint.ts">
  Run Uint examples in the interactive playground
</Card>

<Tabs>
  <Tab title="Effect Schema">
    ```ts theme={null}
    import { UintSchema } from '@tevm/voltaire/Uint/effect'

    const u = UintSchema.from(255n)
    u.toHex(false) // '0xff'
    ```
  </Tab>
</Tabs>

## Output Format

Hex strings are **minimal** - no unnecessary leading zeros:

```typescript theme={null}
Uint.toHex(Uint(0n))      // "0x0"
Uint.toHex(Uint(1n))      // "0x1"
Uint.toHex(Uint(15n))     // "0xf"
Uint.toHex(Uint(16n))     // "0x10"
Uint.toHex(Uint(255n))    // "0xff"
Uint.toHex(Uint(256n))    // "0x100"
```

### Always Lowercase

```typescript theme={null}
Uint.toHex(Uint(0xdeadbeefn))  // "0xdeadbeef"
```

### Always Has 0x Prefix

```typescript theme={null}
// Never returns without prefix
Uint.toHex(Uint(255n))  // "0xff" (not "ff")
```

## Usage Patterns

### Logging and Debugging

```typescript theme={null}
const value = Uint(12345n)
console.log(`Value: ${Uint.toHex(value)}`)  // "Value: 0x3039"
```

### Ethereum RPC

```typescript theme={null}
// Format for JSON-RPC
const balance = Uint(1000000000000000000n)
const rpcValue = Uint.toHex(balance)  // "0xde0b6b3a7640000"

await eth_sendTransaction({
  value: rpcValue
})
```

### Storage Keys

```typescript theme={null}
const slot = Uint(5n)
const key = Uint.toHex(slot)  // "0x5"
```

## See Also

* [fromHex](/primitives/uint256/from-hex) - Parse hex string
* [toString](/primitives/uint256/to-string) - Convert to string (any radix)
* [toBigInt](/primitives/uint256/to-bigint) - Convert to BigInt
