Register A Domain
Check availability and register a domain with or without DNS records
Registration is paid from your NFSC balance first; any remainder is charged to
the credit card saved on your Namefi profile. Card charges are at least $1.00 —
when the shortfall is smaller, the card is charged $1.00 and correspondingly
less NFSC is used. If neither rail covers the price, the request fails with
links to top up NFSC or save a card. The order response's payments array
shows the planned split (legs are charged asynchronously after the order is
created).
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);
}