| description | 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.md.
Calculate the fees for a domain with:
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.
Registering a domain requires approving the fee transfer on the BYOC contract first:
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:
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 mints a new domain. domain, to and byocSymbol are required; parentDomain and subscriptionYears are optional.
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}`)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.
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.
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 %}
Use find to retrieve a single domain. It resolves to null when the domain does not exist:
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 |