【问题标题】:web3 get name from addressweb3 从地址获取名称
【发布时间】:2021-12-05 14:19:44
【问题描述】:
    import Web3 from "web3";

    
    useEffect(() => {
    const web3 = new Web3(window.ethereum);

    web3.eth.ens.getAddress("ethereum.eth").then(function (address) {
        console.log(address);
    });
    }, []);

在这里使用此代码我从以太名称获得address 有什么办法可以从地址中获取名字

    web3.eth.ens.getOwner("0xc74E8eFaFE54481bD109f97422AeBca607499f57").then(function (address) {
        console.log(address);
    });

我正在尝试上面的代码,但它不起作用 如果我输入0xc74E8eFaFE54481bD109f97422AeBca607499f57 我应该得到ethereum.eth 请看看我怎样才能得到这个

【问题讨论】:

    标签: ethereum web3 metamask


    【解决方案1】:

    ENS documentation 可以看出,web3.js 无法执行“反向解析”,即从地址获取 ENS 名称。但是,您可以通过 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-17
      • 2018-08-01
      • 2022-09-23
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-08-02
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多