[英]web3 get name from address
import Web3 from "web3";
useEffect(() => {
const web3 = new Web3(window.ethereum);
web3.eth.ens.getAddress("ethereum.eth").then(function (address) {
console.log(address);
});
}, []);
here using this code i am getting address
from ether name is there any way i can get name from address在这里使用此代码我从以太名称获取
address
有什么方法可以从地址获取名称
web3.eth.ens.getOwner("0xc74E8eFaFE54481bD109f97422AeBca607499f57").then(function (address) {
console.log(address);
});
I am trying above piece of code but it is not working if i input 0xc74E8eFaFE54481bD109f97422AeBca607499f57
i should get ethereum.eth
please take a look how can i get this我正在尝试上面的一段代码,但是如果我输入
0xc74E8eFaFE54481bD109f97422AeBca607499f57
我应该得到ethereum.eth
请看看我怎么能得到这个
As you can see from the ENS documentation , web3.js can't performed "reversed resolution", ie getting a ENS name from an address.从ENS 文档中可以看出,web3.js 无法执行“反向解析”,即从地址获取 ENS 名称。 However, you can do this from the ensjs API like this:
但是,您可以通过ensjs API 执行此操作,如下所示:
const address = '0xc74E8eFaFE54481bD109f97422AeBca607499f57';
var name = await ens.getName(address)
// Check to be sure the reverse record is correct.
if(address != await ens.name(name).getAddress()) {
name = null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.