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

ENS reverse lookup #2683

Closed
nivida opened this issue Apr 15, 2019 · 15 comments
Closed

ENS reverse lookup #2683

nivida opened this issue Apr 15, 2019 · 15 comments
Labels
2.x 2.0 related issues Feature Request Stale Has not received enough activity

Comments

@nivida
Copy link
Contributor

nivida commented Apr 15, 2019

Description

Implement the ENS reverse lookup.

Docs: https://docs.ens.domains/contract-api-reference/reverseregistrar

@princesinha19
Copy link
Contributor

@nivida I think the ENS registry is also missing.
Docs: https://docs.ens.domains/contract-api-reference/ens

you can add in this issue or if you want I can create a new issue.

@nivida
Copy link
Contributor Author

nivida commented Apr 16, 2019

The ens registry isn't missing. https://web3js.readthedocs.io/en/1.0/web3-eth-ens.html#registry

@princesinha19
Copy link
Contributor

@nivida all methods are not present, which is listed in this docs.
Only registry is there.

@nivida
Copy link
Contributor Author

nivida commented Apr 16, 2019

Yep, there are some missing new methods. I was in contact with the ENS team and told them to check it. I'll do this together with the ENS reverse lookup because it isn't a big thing to add these methods.

The current registry: https://github.com/ethereum/web3.js/blob/1.0/packages/web3-eth-ens/src/contracts/Registry.js

@jefflau

@ellis2323
Copy link

Is the reverse on the roadmap? or can we create a PR ?

@jamesmorgan
Copy link

This would be great, I see its be flagged for the 2.x branch - I guess this means we wont make it into 1.x?

@jamesmorgan
Copy link

It would be really awesome if this was priorities to be fixed - the current way, from my understanding, to allow users to claim subdomains on ENS is to send them to the ENS manager site or write some custom code, would be great if this was part of native we3js

@gpersoon
Copy link

I've created a code snippet to do a reverse lookup.

async function Reverse(address) {        
    var lookup=address.toLowerCase().substr(2) + '.addr.reverse'
    var ResolverContract=await web3.eth.ens.resolver(lookup);
    var nh=namehash.hash(lookup);
    var name=await ResolverContract.methods.name(nh).call()
    return name;
}    

@github-actions
Copy link

github-actions bot commented Jul 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions

@github-actions github-actions bot added the Stale Has not received enough activity label Jul 4, 2020
@mqklin
Copy link

mqklin commented Sep 24, 2020

@x48-crypto check this comment

@lucadonnoh
Copy link

any update?

@blankey1337
Copy link

blankey1337 commented Jan 5, 2022

Here is a snippet of the above with the recommended forward lookup to avoid imposters:

async function reverseENSLookup(address: string, web3: Web3) {        
  let lookup = address.toLowerCase().substr(2) + '.addr.reverse'
  let ResolverContract = await web3.eth.ens.getResolver(lookup);
  let nh = namehash.hash(lookup);
  try {
    let name = await ResolverContract.methods.name(nh).call();
    if (name && name.length) {
      const verifiedAddress = await web3.eth.ens.getAddress(name);
      if (verifiedAddress && verifiedAddress.toLowerCase() === address.toLowerCase()) {
        return name;
      }
    }
  } catch(e) { }
}  

@giannisftaras
Copy link

Here is a snippet of the above with the recommended forward lookup to avoid imposters:

async function reverseENSLookup(address: string, web3: Web3) {        
  let lookup = address.toLowerCase().substr(2) + '.addr.reverse'
  let ResolverContract = await web3.eth.ens.getResolver(lookup);
  let nh = namehash.hash(lookup);
  try {
    let name = await ResolverContract.methods.name(nh).call();
    if (name && name.length) {
      const verifiedAddress = await web3.eth.ens.getAddress(name);
      if (verifiedAddress && verifiedAddress.toLowerCase() === address.toLowerCase()) {
        return name;
      }
    }
  } catch(e) { }
}  

I am trying to implement your snippet using Web3JS from a CDN but I am getting an error "namehash: is not defined". The namehash object appears to be implemented in the library but I am not able to call it. Apparently I am missing something...

@gpersoon
Copy link

Namehash can be found here: https://www.npmjs.com/package/@ensdomains/eth-ens-namehash

@numtel
Copy link

numtel commented Nov 5, 2022

I didn't want to import any extra modules to my frontend so I use this function:

async function ensReverse(address) {
  const web3 = new Web3('https://eth.public-rpc.com/');
  const namehash = await web3.eth.call({
    to: '0x084b1c3c81545d370f3634392de611caabff8148', // ENS: Reverse Registrar
    data: web3.eth.abi.encodeFunctionCall({
      name: 'node', type: 'function',
      inputs: [{type: 'address', name: 'addr'}]
    }, [address])
  });
  return web3.eth.abi.decodeParameter('string', await web3.eth.call({
    to: '0xa2c122be93b0074270ebee7f6b7292c7deb45047', // ENS: Default Reverse Resolver
    data: web3.eth.abi.encodeFunctionCall({
      name: 'name', type: 'function',
      inputs: [{type: 'bytes32', name: 'hash'}]
    }, [namehash])
  }));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x 2.0 related issues Feature Request Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

10 participants