// tools/checkAvailability.ts
export async function checkCeloNameAvailability(name: string): Promise<{
name: string;
available: boolean;
}> {
const normalizedName = name.endsWith('.celo') ? name : `${name}.celo`;
// Query the L2 Registry
const node = namehash(normalizedName);
const owner = await l2Registry.owner(node);
return {
name: normalizedName,
available: owner === ethers.constants.AddressZero,
};
}
// tools/getRegistrationPrice.ts
export async function getRegistrationPrice(
name: string,
years: number = 1
): Promise<{
name: string;
years: number;
baseWei: string;
totalWei: string;
totalEth: string;
}> {
const normalizedName = name.replace('.celo', '');
const duration = years * 365 * 24 * 60 * 60; // seconds
const [price] = await l2Registrar.registerPrice(normalizedName, duration);
return {
name: `${normalizedName}.celo`,
years,
baseWei: price.toString(),
totalWei: price.toString(),
totalEth: ethers.utils.formatEther(price),
};
}
// tools/registerName.ts
export async function registerCeloName(
name: string,
years: number,
owner: string
): Promise<{
success: boolean;
name: string;
owner: string;
commitTxHash: string;
registerTxHash: string;
}> {
const normalizedName = name.replace('.celo', '');
const duration = years * 365 * 24 * 60 * 60;
// Generate commitment
const secret = ethers.utils.randomBytes(32);
const commitment = await l2Registrar.makeCommitment(
normalizedName,
owner,
duration,
secret,
await l2Registrar.resolver(),
[],
false,
0
);
// Commit
const commitTx = await l2Registrar.commit(commitment);
const commitReceipt = await commitTx.wait();
// Wait for min commitment age (usually 60 seconds)
await new Promise(r => setTimeout(r, 60000));
// Register
const [price] = await l2Registrar.registerPrice(normalizedName, duration);
const registerTx = await l2Registrar.register(
normalizedName,
owner,
duration,
secret,
await l2Registrar.resolver(),
[],
false,
0,
{ value: price }
);
const registerReceipt = await registerTx.wait();
return {
success: true,
name: `${normalizedName}.celo`,
owner,
commitTxHash: commitReceipt.transactionHash,
registerTxHash: registerReceipt.transactionHash,
};
}