ensdomains / ensjs

ENS javascript library for contract interaction
MIT License
129 stars 59 forks source link

Resolving ENS name associated with an ENS NFT #184

Open coopermaruyama opened 5 months ago

coopermaruyama commented 5 months ago

I have looked through the docs and codebase and have not been able to find a way to find out the ENS name associated with an ENS NFT, given I know the token ID and contract address of the NFT. Is this supported via the SDK and I'm just missing something?

For example, I'm looking for a way to successfully implement the following hypothetical function using the SDK:

const name = await getENSName({
  contractAddress: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
  tokenId: '79233663829379634837589865448569342784712482819484549289560981379859480642508'
})

console.log(name) // "vitalik.eth"

Is this possible with the SDK? If not, is it possible to do this at all? I was expecting to just be able to query tokenURI() like with any other ERC-721 contract but it looks like the implementation used by ENS does not implement this. Any info would be appreciated, thanks.

talentlessguy commented 5 months ago

You could resolve a name by calling an ownerOf(tokenId) and then doing reverse resolution

coopermaruyama commented 5 months ago

that will only give me the name that the owner set as their primary. if someone has more than one then i'll get the wrong one on the rest.