Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions src/commands/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type BatchOperation = z.infer<typeof batchOperationSchema>

type SetContext = Context & { options: { resolver?: string } }

const RESOLVER_SELECTION_HINT =
"By default, the generated transaction targets the name's current resolver. Use --resolver to override it."
const REVERSE_NAMESPACE = 'addr.reverse'

async function resolveTargetResolver(c: SetContext, name: string): Promise<`0x${string}`> {
Expand Down Expand Up @@ -125,9 +127,7 @@ const resolverOption = z.object({
resolver: z
.string()
.optional()
.describe(
'Resolver address to target. If omitted, the resolver is read from the Universal Resolver; if none is set, the command fails.',
),
.describe("Resolver contract to target instead of the name's current resolver"),
})

export const setCommands = Cli.create('set', {
Expand Down Expand Up @@ -157,8 +157,8 @@ export const setCommands = Cli.create('set', {
},
})
.command('address', {
description:
'Generate calldata to set the address record for an ENS name. Resolves the target resolver via the Universal Resolver unless --resolver is passed.',
description: 'Generate calldata to set an address record',
hint: RESOLVER_SELECTION_HINT,
args: z.object({
name: z.string().describe('ENS name (e.g. myname.eth)'),
}),
Expand All @@ -171,6 +171,13 @@ export const setCommands = Cli.create('set', {
}),
),
env: globalEnv,
examples: [
{
args: { name: 'myname.eth' },
options: { address: '0x0000000000000000000000000000000000000001' },
description: 'Set the default Ethereum address',
},
],
async run(c) {
const name = validateName(c.args.name)
const resolverAddress = await resolveTargetResolver(c, name)
Expand All @@ -181,8 +188,8 @@ export const setCommands = Cli.create('set', {
},
})
.command('text', {
description:
'Generate calldata to set a text record for an ENS name. Resolves the target resolver via the Universal Resolver unless --resolver is passed.',
description: 'Generate calldata to set a text record',
hint: RESOLVER_SELECTION_HINT,
args: z.object({
name: z.string().describe('ENS name (e.g. myname.eth)'),
}),
Expand All @@ -193,6 +200,13 @@ export const setCommands = Cli.create('set', {
}),
),
env: globalEnv,
examples: [
{
args: { name: 'myname.eth' },
options: { key: 'url', value: 'https://example.com' },
description: 'Set a URL text record',
},
],
async run(c) {
const name = validateName(c.args.name)
const resolverAddress = await resolveTargetResolver(c, name)
Expand All @@ -202,8 +216,8 @@ export const setCommands = Cli.create('set', {
},
})
.command('contenthash', {
description:
'Generate calldata to set the content hash for an ENS name. Resolves the target resolver via the Universal Resolver unless --resolver is passed.',
description: 'Generate calldata to set a contenthash record',
hint: RESOLVER_SELECTION_HINT,
args: z.object({
name: z.string().describe('ENS name (e.g. myname.eth)'),
}),
Expand All @@ -213,6 +227,15 @@ export const setCommands = Cli.create('set', {
}),
),
env: globalEnv,
examples: [
{
args: { name: 'myname.eth' },
options: {
hash: '0xe30101701220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
},
description: 'Set an IPFS contenthash',
},
],
async run(c) {
const name = validateName(c.args.name)
const resolverAddress = await resolveTargetResolver(c, name)
Expand All @@ -222,8 +245,8 @@ export const setCommands = Cli.create('set', {
},
})
.command('batch', {
description:
'Generate multicall calldata to set multiple records in a single transaction. Pass a JSON array of operations. Resolves the target resolver via the Universal Resolver unless --resolver is passed.',
description: 'Generate multicall calldata to set multiple records',
hint: `Pass a JSON array of record operations. ${RESOLVER_SELECTION_HINT}`,
args: z.object({
name: z.string().describe('ENS name (e.g. myname.eth)'),
}),
Expand All @@ -237,6 +260,15 @@ export const setCommands = Cli.create('set', {
}),
),
env: globalEnv,
examples: [
{
args: { name: 'myname.eth' },
options: {
data: `'[{"type":"text","key":"url","value":"https://example.com"}]'`,
},
description: 'Set records in a single transaction',
},
],
async run(c) {
const name = validateName(c.args.name)
const resolverAddress = await resolveTargetResolver(c, name)
Expand Down
Loading