Skip to content

Conversation

nexxeln
Copy link

@nexxeln nexxeln commented Jul 8, 2025

migrate setResolver to support namechain contracts while maintaining backwards compatibility.

the function now accepts registry addresses in addition to 'registry' and 'namewrapper' string literals.

for namechain contracts, it uses labelhash instead of namehash and calls setResolver(tokenid, resolver) with the appropriate abi.

should we extract the namechain abi snippet to a separate file like ../../contracts/namechain.js similar to how nameWrapper has? currently it's defined inline because its very simple.

Copy link

pkg-pr-new bot commented Jul 8, 2025

Open in StackBlitz

npm i https://pkg.pr.new/ensdomains/ensjs/@ensdomains/ensjs@248

commit: 3cf1a35

name: string;
/** Contract to set resolver on - can be 'registry', 'nameWrapper', or an address of a namechain registry */
contract: "registry" | "nameWrapper" | Address;
/** Resolver address to set */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend turning contract into optional "registry" | "name wrapper" and adding a new parameter called registryAddress to make this more descriptive and precise. You can use discriminated unions to keep it type safe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should think about it more. i'll leave it as is for now

Copy link
Member

@svemat01 svemat01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reformat the file. It seems like the configuration wasn't applied, and it switched from spaces to tabs

Copy link

}

// Handle namechain contracts
if (registryAddress && !isAddress(registryAddress)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to check if registryAddress exists. isAddres will return false if registryAddress does not exist. Also this condition will fail if registryAddress is empty.

TLDR. Just check if registryAddres is address.

const baseParams = {
address,
functionName,
address: registryAddress!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid forcing the value or registryAddress. Should add a guard function before this is isAddress does not satisfy it.

e.g. function checkAddress(x: unknown): x is Address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants