> For the complete documentation index, see [llms.txt](https://docs.metanames.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metanames.app/developers/domains.md).

# Domains

Register, renew, transfer and find domains

All examples assume a configured `metaNamesSdk` instance. Registering, renewing and transferring are write operations, so a signing strategy must be set first — see [Getting started](/developers/getting-started.md).

### Calculate fees

Calculate the fees for a domain with:

```typescript
const domainName = 'supercool.mpc'
const { fees, symbol, address, feesLabel } = await metaNamesSdk.domainRepository.calculateMintFees(domainName, 'ETH')
console.log(`Fees for ${domainName}: ${feesLabel} ${symbol} (raw: ${fees}, BYOC contract: ${address})`)
```

`fees` is the raw on-chain amount as a `BN`, while `feesLabel` is the same amount formatted with the token's decimals. `address` is the BYOC contract the fees are paid from.

The fee returned covers **one** year. Multiply it yourself if you intend to register for longer.

### Approve fees

Registering a domain requires approving the fee transfer on the BYOC contract first:

```typescript
const domainName = 'supercool.mpc'
const { transactionHash, fetchResult } = await metaNamesSdk.domainRepository.approveMintFees(domainName, 'ETH')
console.log(`Transaction hash: ${transactionHash}`)
const result = await fetchResult
console.log(`Fees approval submitted: ${result}`)
```

Pass a third argument to approve several years at once:

```typescript
await metaNamesSdk.domainRepository.approveMintFees(domainName, 'ETH', 3)
```

Wait for `fetchResult` to settle before registering — the registration fails if the approval has not been finalised on chain.

### Register a domain

`register` mints a new domain. `domain`, `to` and `byocSymbol` are required; `parentDomain` and `subscriptionYears` are optional.

#### Register a new domain without a parent

```typescript
const { transactionHash, fetchResult } = await metaNamesSdk.domainRepository.register({
  domain: 'supercool.mpc',
  to: 'recipientAddress',
  byocSymbol: 'ETH',
})
console.log(`Transaction hash: ${transactionHash}`)
const result = await fetchResult
console.log(`Domain registration submitted: ${result}`)
```

#### Register a subdomain

```typescript
const { transactionHash, fetchResult } = await metaNamesSdk.domainRepository.register({
  domain: 'subname',
  to: 'recipientAddress',
  byocSymbol: 'ETH',
  parentDomain: 'supercool.mpc',
  subscriptionYears: 2,
})
console.log(`Transaction hash: ${transactionHash}`)
const result = await fetchResult
console.log(`Domain registration submitted: ${result}`)
```

Replace `'supercool.mpc'`, `'recipientAddress'` and `'ETH'` with actual values. To register several domains in a single transaction, pass an array to `registerBatch`.

### Renew a domain

```typescript
const { transactionHash, fetchResult } = await metaNamesSdk.domainRepository.renew({
  domain: 'supercool.mpc',
  payer: 'payerAddress',
  byocSymbol: 'ETH',
  subscriptionYears: 1,
})
console.log(`Transaction hash: ${transactionHash}`)
const result = await fetchResult
console.log(`Domain renewal submitted: ${result}`)
```

Renewal fees also have to be approved beforehand, in the same way as registration.

### Transfer a domain

```typescript
const { transactionHash, fetchResult } = await metaNamesSdk.domainRepository.transfer({
  domain: 'supercool.mpc',
  from: 'currentOwnerAddress',
  to: 'recipientAddress',
})
console.log(`Transaction hash: ${transactionHash}`)
const result = await fetchResult
console.log(`Domain transfer submitted: ${result}`)
```

{% hint style="warning" %}
Transfers are irreversible. Make sure the destination wallet is accessible, or the domain will be lost.
{% endhint %}

### Finding domain information

Use `find` to retrieve a single domain. It resolves to `null` when the domain does not exist:

```typescript
const domain = await metaNamesSdk.domainRepository.find('supercool.mpc')
if (!domain) console.log('Domain not found')
else console.log(`Domain data: ${JSON.stringify(domain)}`)
```

Other lookups available on the domain repository:

| Method                      | Returns                                                                          |
| --------------------------- | -------------------------------------------------------------------------------- |
| `findByOwner(ownerAddress)` | Every domain held by an address                                                  |
| `getAll()`                  | Every registered domain                                                          |
| `count()`                   | The number of registered domains                                                 |
| `getOwners()`               | The list of addresses holding at least one domain                                |
| `analyze(domainName)`       | The normalised `name`, its `parentId` and the `tld`, without hitting the network |
