Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register a subdomain #223

Open
pikonha opened this issue Jan 27, 2025 · 1 comment
Open

Register a subdomain #223

pikonha opened this issue Jan 27, 2025 · 1 comment

Comments

@pikonha
Copy link

pikonha commented Jan 27, 2025

I'm looking for ways to register a subdomain of an ENS domain which isn't supported by this library yet.

if (nameType !== 'eth-2ld')
  throw new UnsupportedNameTypeError({
    nameType,
    supportedNameTypes: ['eth-2ld'],
    details: 'Only 2ld-eth name registration is supported',
  })

Is it something expected to be supported soon? If so, I'd be down to work on it.

@pikonha
Copy link
Author

pikonha commented Jan 27, 2025

The way I thought of implementing it is through the NameWrapper setSubnodeRecord function like so:

export const makeFunctionData = <
  TChain extends ChainWithEns,
  TAccount extends Account | undefined,
>(
  wallet: ClientWithAccount<Transport, TChain, TAccount>,
  { value, ...args }: RegisterNameDataParameters,
): RegisterNameDataReturnType => {
  const nameType = getNameType(args.name)

  switch (nameType) {
    case 'eth-2ld': {
      const labels = args.name.split('.')
      wrappedLabelLengthCheck(labels[0])

      return {
        to: getChainContractAddress({
          client: wallet,
          contract: 'ensEthRegistrarController',
        }),
        data: encodeFunctionData({
          abi: ethRegistrarControllerRegisterSnippet,
          functionName: 'register',
          args: makeRegistrationTuple(args),
        }),
        value,
      }
    }
    case 'eth-subname': {
      return {
        to: getChainContractAddress({
          client: wallet,
          contract: 'ensNameWrapper',
        }),
        data: encodeFunctionData({
          abi: nameWrapperSetSubnodeRecordSnippet,
          functionName: 'setSubnodeRecord',
          args: makeSubdomainRegistrationTuple(args),
        }),
        value,
      }
    }
    default:
      throw new UnsupportedNameTypeError({
        nameType,
        supportedNameTypes: ['eth-2ld', 'eth-subname'],
        details: 'Unsupported name type',
      })
  }
}

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

No branches or pull requests

1 participant