feat: added contenthash to edit commands d907465b
Steve · 2025-10-31 10:28 2 file(s) · +92 −0
src/commands/edit.ts +57 −0
4 4
	setResolver as setResolverRecord,
5 5
	setPrimaryName as setPrimaryNameRecord,
6 6
	setAbiRecord,
7 +
	setContentHashRecord,
7 8
} from "@ensdomains/ensjs/wallet";
8 9
import { normalize } from "viem/ens";
9 10
import { spinner, walletClient } from "../utils";
269 270
		);
270 271
	}
271 272
}
273 +
274 +
export async function setContentHash(options: {
275 +
	name: string;
276 +
	contentHash: string;
277 +
	resolverAddress?: string;
278 +
}) {
279 +
	try {
280 +
		spinner.start();
281 +
		const wallet = await walletClient();
282 +
283 +
		if (!wallet) {
284 +
			spinner.stop();
285 +
			console.error(
286 +
				"Error: Wallet not configured. Please set ATLAS_PRIVATE_KEY environment variable.",
287 +
			);
288 +
			return;
289 +
		}
290 +
291 +
		// Get resolver if not provided
292 +
		let resolverAddress = options.resolverAddress;
293 +
		if (!resolverAddress) {
294 +
			const { ensClient } = await import("../utils");
295 +
			const resolver = await ensClient.getEnsResolver({
296 +
				name: normalize(options.name),
297 +
			});
298 +
			resolverAddress = resolver || undefined;
299 +
		}
300 +
301 +
		if (!resolverAddress) {
302 +
			spinner.stop();
303 +
			console.error("Error: No resolver found for this name");
304 +
			return;
305 +
		}
306 +
307 +
		const hash = await setContentHashRecord(wallet, {
308 +
			name: options.name,
309 +
			contentHash: options.contentHash === "null" ? null : options.contentHash,
310 +
			resolverAddress: resolverAddress as `0x${string}`,
311 +
		});
312 +
313 +
		spinner.stop();
314 +
		if (options.contentHash === "null") {
315 +
			console.log(`✓ Content hash cleared successfully`);
316 +
		} else {
317 +
			console.log(`✓ Content hash set successfully`);
318 +
		}
319 +
		console.log(`Transaction hash: ${hash}`);
320 +
	} catch (error) {
321 +
		const e = error as { shortMessage?: string; message: string };
322 +
		spinner.stop();
323 +
		console.error("Error setting content hash:", e.shortMessage || e.message);
324 +
		console.error(
325 +
			"If you are receiving HTTP errors consider setting ETH_RPC_URL as an environemnt variable",
326 +
		);
327 +
	}
328 +
}
src/index.ts +35 −0
22 22
	setResolver as setResolverCmd,
23 23
	setPrimaryName as setPrimaryNameCmd,
24 24
	setAbi as setAbiCmd,
25 +
	setContentHash as setContentHashCmd,
25 26
} from "./commands";
26 27
27 28
const resolve = command({
326 327
	},
327 328
});
328 329
330 +
const editContentHash = command({
331 +
	name: "contenthash",
332 +
	description:
333 +
		"Set content hash for an ENS name (use 'null' to clear the record)",
334 +
	args: {
335 +
		name: positional({
336 +
			type: string,
337 +
			description: "Target ENS name",
338 +
		}),
339 +
		contentHash: positional({
340 +
			type: string,
341 +
			description:
342 +
				"Content hash value (e.g. ipfs://, ipns://, or 'null' to clear)",
343 +
		}),
344 +
		resolverAddress: option({
345 +
			type: optional(string),
346 +
			long: "resolver",
347 +
			short: "r",
348 +
			description:
349 +
				"Resolver address (optional, will auto-detect if not provided)",
350 +
		}),
351 +
	},
352 +
	handler: async (args) => {
353 +
		if (!args.name || args.contentHash === undefined) {
354 +
			console.log(
355 +
				"Please provide all required arguments: `atlas edit contenthash <name> <contentHash>`",
356 +
			);
357 +
			return;
358 +
		}
359 +
		await setContentHashCmd(args);
360 +
	},
361 +
});
362 +
329 363
const edit = subcommands({
330 364
	name: "edit",
331 365
	description: "Edit records for an ENS name",
335 369
		resolver: editResolver,
336 370
		primaryName: editPrimaryName,
337 371
		abi: editAbi,
372 +
		contenthash: editContentHash,
338 373
	},
339 374
});
340 375