How to get ENS domain address with Moralis

I am using Moralis for my DApp, after I login with Meatmask. I wonder how to get my registered ENS domain address. From the logged user object, I can not find any useful info.

  const serverUrl = "https://xxxxx/server";
  const appId = "YOUR_APP_ID";
  Moralis.start({ serverUrl, appId });

  // add from here down
  async function login() {
    let user = Moralis.User.current();
    if (!user) {
      user = await Moralis.authenticate();
    }
    console.log("logged in user:", user);
    const userEthNFTs = await Moralis.Web3API.account.getNFTs();
    console.log("====== userEthNFTs: ", userEthNFTs);
  }

I do see my ENS nft got printed out, but I do not see any β€œname” in it, it only shows:

amount: "1"​​​
block_number: "13809918"​​​
block_number_minted: "13809918"​​​
contract_type: "ERC721"​​​
frozen: 0​​​
is_valid: 0​​​
metadata: null​​​
name: ""​​​
owner_of: "0xf...4"​​​
symbol: ""​​​
synced_at: null​​​
syncing: 1​​​
token_address: "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85"​​​
token_id: "9215...."​​​
token_uri: null

I did a little more research on this, and found out ethers.js has lookupAddress function which can do it, but this reverse lookup feature is not supported in web3js . However, Moralis only has web3js provider, is there any plans to add ethers provider?

Thanks

we plan on adding etherjs in the future

you want to get the ENS domain starting from address?

for that you can use from https://admin.moralis.io/web3Api: GET ​/resolve​/{address}​/reverse Return the ENS domain when available (Only for ETH)

1 Like