Managing names

Registrations & renewals

Registering names

id.js makes it very simple to register and renew domains. ENS names will use the new controller, so they're ERC-1155 names.

Check pricing & availability


const name = 'bob.forever';
const [registration, price, requireCommitment] = await Promise.all([
  id.getRegistration(name),
  id.getPrice(name),
  id.requiresCommitment(name)
]);

if (registration.status === 'unregistered') {
  // register name
} else {
  console.log(`name is already registered :(`);
  // .forever style domains expiry is always 0
  console.log(`expires: ${registration.expiry}`);
  console.log(`current owner: ${registration.owner}`);
  console.log(`is recurring (false for .forever): ${price.recurring}`);
}

Make a commitment

const duration = 365 * 24 * 60 * 60; // 1 year
const secret = '0x1234....'; // random 32 bytes

if (requireCommitment) {
  let commitment;
  commitment = await id.makeCommitment(name, {
    duration,
    secret
  });
  
  // submit TX
  let tx = await id.commit(name, commitment);
  await tx.wait();

  const minAge = await id.getMinCommitmentAge(name);
  // wait at least minAge seconds before registering
  // show a progress bar instead in the UI!
  // (it's better to check the latest block timestamp to make sure)
  await new Promise(resolve => setTimeout(resolve, minAge));
}

Register name

If you used getPrice like shown above, you can use price.buffered to get the price with a 3% buffer to account for price fluctuations in the USD oracle.

const tx = await id.register(name, {
  duration,
  secret,
  value: price.buffered
});
await tx.wait();

That's it! You just learned how to register a name for Impervious domains, Forever and ENS!

Renewing names

Not all names require renewal. For example, Forever names are registered forever.

const [registration, price] = await Promise.all([
  id.getRegistration(name),
  id.getPrice(name)
]);

if (registration.status !== 'registered') {
  console.log('name is not registered')
} else if (!price.recurring) {
  console.log('name does not expire')
} else {
   const tx = await id.renew(name, {
     duration: 365 * 24 * 60 * 60, // 1 year
     value: price.buffered
   });
   await tx.wait();
}
Previous
Querying & updating records