# Address Input

> Recipient field that takes an address or ENS name, resolves names, and catches checksum typos.

- Install: `npx shadcn@latest add @0xui/address-input`
- Registry JSON: https://0xui.io/r/address-input.json
- Source: https://github.com/fimbul-lab/0xui/blob/main/registry/default/components/address-input.tsx

Type or paste an address or an ENS name. Names resolve on mainnet once typing pauses, with the avatar and resolved address shown. Mixed-case addresses must match their checksum, which catches most single-character typos. Problems show after the field loses focus, not while typing.

## Installation

```bash
npx shadcn@latest add @0xui/address-input
```

## Usage

```tsx
import { AddressInput } from "@/components/address-input";

const [text, setText] = useState("");
const [recipient, setRecipient] = useState<Address>();

<AddressInput
  value={text}
  onValueChange={setText}
  onResolve={(state) => setRecipient(state.address)}
/>;
```

Always send to `state.address`, never to the raw text. It is `undefined` until the input is a valid address or a resolved name.

## Private addresses

With `shielded`, the field also accepts a private `0zk…` address, for a recipient inside a private balance. It is checked by length and by its own checksum, so one wrong character is caught. The result is in `state.shieldedAddress`, and `state.address` stays `undefined`.

```tsx
<AddressInput
  value={text}
  onValueChange={setText}
  shielded
  onResolve={(state) => setRecipient(state.shieldedAddress ?? state.address)}
/>
```

A private address is never sent to an ENS resolver or any other lookup. Without `shielded`, a pasted `0zk` address is turned down with "Private (0zk) addresses can't be used here."

The format is Railgun's: `0zk`, 127 characters, bech32m. `isShieldedAddress` in `lib/0xui-utils` is the same check on its own.

## States

`data-phase` on the root holds the current state.

| Phase | Meaning |
| --- | --- |
| `empty` | Nothing typed. |
| `incomplete` | Not a full address or name yet. Reported after blur. |
| `resolving` | Looking up an ENS name. |
| `valid` | `state.address` is set. For names, the resolved address is shown under the field. For addresses, the ENS name is shown. |
| `invalid` | Bad checksum, too long, or not a valid name. Reported after blur. |
| `not-found` | The name has no address. Reported right away. |

## Props

Also accepts `<input>` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | — | Text in the field. |
| `onValueChange` | `(value) => void` | — | Called on every change. |
| `onResolve` | `(state) => void` | — | Called when validation settles on a new result. |
| `label` | `string` | `"Recipient"` | Accessible label. |
| `showPaste` | `boolean` | `true` | Paste button while empty. |
| `shielded` | `boolean` | `false` | Also accept private `0zk…` addresses. |

Headless: `useAddressInput(value, { shielded })` returns the same state.
