# registry.deploy

> For the complete documentation index, see [llms.txt](https://ensforge.com/llms.txt).

Deploys an ENSv2 UserRegistry, optionally attaching it as a name's subregistry. Options, result, errors and examples for registry.deploy.

Source: https://ensforge.com/docs/reference/sdk/registry/deploy

<ApiMeta kind="Write" stability="stable" since="1.0.0" source="packages/sdk/src/actions/registry/deploy/index.ts#L61" />

Deploys an ENSv2 UserRegistry, optionally attaching it as a name's subregistry. Resolves once the transaction is submitted.

## When to use [#when-to-use]

Use to set up the registry for a name's children ahead of time, or with custom roles. Use [`deploySync`](/docs/reference/sdk/registry/deploy#wait-for-the-receipt-with-deploysync) to wait for the receipt.

## Details [#details]

- A verifiable proxy of the deployment's UserRegistry, at an address known before sending
  (`plan.deploys`, returned as `registry`).
- `owner` (the signer by default) gets every root role; `emancipated` withholds the roles
  that would let owners take children back.
- `attachTo` makes it that name's subregistry in the same plan.

## Signature [#signature]

```ts
function deploy(
  client: Like,
  options: deploy.Options & Write.Options,
): Promise<deploy.ReturnType>
```

Call it as `ens.registry.deploy(options)` on a client, or `Actions.registry.deploy(client, options)`.

## Parameters [#parameters]

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `owner` | `string` | the signing account | Account that gets the root roles. |
| `grants` | `readonly { account: string; roles: readonly Role.Name[] \| bigint }[]` |  | Extra root role grants, by role name or bitmap. |
| `emancipated` | `boolean` |  | Withhold the roles that would let the owners take children back. |
| `attachTo` | `string` |  | ENSv2 name to attach it to as subregistry. Normalized automatically. |
| `salt` | `bigint` | a random salt | CREATE2 salt; together with the account it decides the address. |

Also takes the [write options](/docs/reference/sdk/client#write-options).

## Returns [#returns]

Resolves to `Write.Result & { readonly registry: Address }`. Submitted hashes, the plan and the new registry's address.

## Errors [#errors]

| Error | Codes | When |
| --- | --- | --- |
| [`InvalidInputError`](/docs/reference/errors/invalid-input-error) | [`INVALID_NAME`](/docs/reference/errors/INVALID_NAME), [`INVALID_ADDRESS`](/docs/reference/errors/INVALID_ADDRESS), [`INVALID_ROLES`](/docs/reference/errors/INVALID_ROLES) | invalid input. |
| [`UnsupportedError`](/docs/reference/errors/unsupported-error) | [`UNSUPPORTED_ON_DEPLOYMENT`](/docs/reference/errors/UNSUPPORTED_ON_DEPLOYMENT), [`UNSUPPORTED_PROTOCOL`](/docs/reference/errors/UNSUPPORTED_PROTOCOL) | without ENSv2, or for an ENSv1 `attachTo`. |
| [`UnauthorizedError`](/docs/reference/errors/unauthorized-error) | [`MISSING_ROLES`](/docs/reference/errors/MISSING_ROLES) | the account may not set the name's subregistry. |
| [`ConfigError`](/docs/reference/errors/config-error) | [`WALLET_NOT_CONFIGURED`](/docs/reference/errors/WALLET_NOT_CONFIGURED) | no signing account is known. |
| [`UserRejectedError`](/docs/reference/errors/user-rejected-error) | [`USER_REJECTED`](/docs/reference/errors/USER_REJECTED) | the user rejects the request. |
| [`WalletError`](/docs/reference/errors/wallet-error) | [`CHAIN_MISMATCH`](/docs/reference/errors/CHAIN_MISMATCH), [`ACCOUNT_NOT_FOUND`](/docs/reference/errors/ACCOUNT_NOT_FOUND) | the wallet is on another chain or has no account to sign with. |
| [`UnsupportedError`](/docs/reference/errors/unsupported-error) | [`WALLET_BATCH_UNSUPPORTED`](/docs/reference/errors/WALLET_BATCH_UNSUPPORTED) | with `mode: "batch"` or a paymaster when the wallet cannot send calls as one batch. |

It can also fail with the errors every write can (`Errors.WriteError`: the common errors plus `InsufficientFundsError`, `TransactionError`, `UnsupportedError`, `UserRejectedError`, `WalletError`).

See [How errors work](/docs/sdk/errors-explained).

## Examples [#examples]

<Tabs groupId="api" items={["Client","Standalone","Effect"]} persist>
<Tab>
```ts title="Deploying a subregistry"
const { registry } = await ens.registry.deploy({ attachTo: "alice.eth" })
```
</Tab>

<Tab>
```ts title="Deploying a subregistry with a standalone call"
import { Actions } from "@ensforge/sdk"

await Actions.registry.deploy(ens, { attachTo: "alice.eth" })
```
</Tab>

<Tab>
```ts title="Deploying a subregistry in an Effect program"
import { Actions } from "@ensforge/sdk/effect"

yield* Actions.registry.deploy(ens, { attachTo: "alice.eth" })
```
</Tab>
</Tabs>

## Plan methods [#plan-methods]

Each method takes the same options as `registry.deploy` and sends nothing. See [Preview before sending](/docs/sdk/preview-before-sending).

| Method | Description |
| --- | --- |
| `registry.deploy.prepare(options)` | Builds the plan without sending anything. |
| `registry.deploy.simulate(options)` | Simulates the plan with `eth_call`, reporting each step. |
| `registry.deploy.estimateGas(options)` | Estimates the gas and ETH the plan needs. |

## Wait for the receipt with `deploySync` [#wait-for-the-receipt-with-deploysync]

Deploys an ENSv2 UserRegistry, optionally attaching it as a name's subregistry. Resolves once the receipt is in.

Use when the next step depends on the change being on-chain.

`registry.deploySync` takes the same options plus [`confirmations` and `timeout`](/docs/reference/sdk/client#sync-options).

Resolves to `Write.SyncResult & { readonly registry: Address }`. Receipts, hashes, the plan and the new registry's address.

<Tabs groupId="api" items={["Client","Standalone","Effect"]} persist>
<Tab>
```ts title="Deploying a subregistry and waiting"
const { receipt } = await ens.registry.deploySync({ attachTo: "alice.eth" })
```
</Tab>

<Tab>
```ts title="Waiting with a standalone call"
import { Actions } from "@ensforge/sdk"

await Actions.registry.deploySync(ens, { attachTo: "alice.eth" })
```
</Tab>

<Tab>
```ts title="Waiting in an Effect program"
import { Actions } from "@ensforge/sdk/effect"

yield* Actions.registry.deploySync(ens, { attachTo: "alice.eth" })
```
</Tab>
</Tabs>

## See also [#see-also]

- [`registry.get`](/docs/reference/sdk/registry/get) to inspect it