logo
Getting started

Register A Domain

Check availability and register a domain with or without DNS records

Before registering, make sure your account has enough NFSC. If you are testing, request faucet tokens first in the Balance and Faucet guide.

Check availability and register

import { createNamefiClient } from '@namefi/api-client';

const client = createNamefiClient({
  authentication: {
    apiKey: process.env.NAMEFI_API_KEY!,
    type: 'API_KEY',
  },
  logger: true,
});

const domain = 'example.com';
const availability = await client.search.checkAvailability({ domain });

if (!availability.availability) {
  throw new Error(`${domain} is not available`);
}

const order = await client.orders.registerDomain({
  normalizedDomainName: domain,
  durationInYears: 1,
});

console.log('Order created', order.id);

Register with DNS records (registerWithRecords)

Use registerWithRecords if you want initial records applied as soon as the order finishes.

import { createNamefiClient } from '@namefi/api-client';

const client = createNamefiClient({
  authentication: {
    apiKey: process.env.NAMEFI_API_KEY!,
    type: 'API_KEY',
  },
  logger: true,
});

const order = await client.orders.registerWithRecords({
  normalizedDomainName: 'example.com',
  durationInYears: 1,
  records: [
    { name: '@', type: 'A', rdata: '203.0.113.10', ttl: 300 },
    { name: 'www', type: 'CNAME', rdata: 'example.com.', ttl: 300 },
  ],
});

console.log('Order created', order.id);

Poll order status

Order processing is asynchronous. Poll orders.getOrder until status is terminal.

import { createNamefiClient } from '@namefi/api-client';
import { setTimeout as sleep } from 'node:timers/promises';

const client = createNamefiClient({
  authentication: {
    apiKey: process.env.NAMEFI_API_KEY!,
    type: 'API_KEY',
  },
  logger: false,
});

const order = await client.orders.registerWithRecords({
  normalizedDomainName: 'example.com',
  durationInYears: 1,
  records: [{ name: '@', type: 'A', rdata: '203.0.113.10', ttl: 300 }],
});

const terminalStatuses = new Set([
  'SUCCEEDED',
  'FAILED',
  'CANCELLED',
  'PARTIALLY_COMPLETED',
]);

while (true) {
  const current = await client.orders.getOrder({ orderId: order.id });
  console.log(`Order ${order.id}:`, current.order.status);

  if (terminalStatuses.has(current.order.status)) {
    break;
  }

  await sleep(5_000);
}

On this page