🌎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.
Calculate fees
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.
Approve fees
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 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
Register a subdomain
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
Renewal fees also have to be approved beforehand, in the same way as registration.
Transfer a domain
Finding domain information
Use find to retrieve a single domain. It resolves to null when the domain does not exist:
Other lookups available on the domain repository:
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
Last updated