1

I am trying to get the DNS records for an ETH domain name, e.g. get the IPv4 addresses for james.eth

I have web3.py installed & working & have an RPC account with Alchemy set up & working. I can get the block address of a ETH name, but I can't find any documentation or example for getting the actual DNS records.

Here's what I have so far

#! /usr/bin/python3

from ens.auto import ns
from ens import ENS

# instantiate w3 instance
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.g.alchemy.com/v2/*********"))
ns = ENS.from_web3(w3)

print(ns.address("james.eth"))

This takes a bit of time, then outputs 0x6Dc43be93a8b5Fd37dC16f24872BaBc6dA5E5e3E, so seems to be working OK.

I know james.eth has IPv4 addresses, but don't know how to get them.

To clarify ... this functionality is available through the gateway eth.link, which I believe is hosted by CloudFlare, but its dog slow and I was told I could improve the performance by using an RCP service. Hence this question.

$ curl -Ss -H 'content-type: application/dns-json' 'https://eth.link/dns-query?type=A&name=james.eth' | jq

This is the code that Bard gave me (with a few fixes!!), but Bard couldn't give me a way to get the dns_contract_address.

#! /usr/bin/python3
from web3 import Web3

# Connect to the Ethereum blockchain
w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.g.alchemy.com/v2/*********"))

# Get the DNS contract address
dns_contract_address = "0x0000000000000000000000000000000000000001"

# Create a contract instance for the DNS contract
dns_contract = w3.eth.contract(address=dns_contract_address)

# Get the name record for "example.com"
name_record = dns_contract.functions.getNameRecord("james.eth").call()

# Print the name record
print(name_record)
James Stevens
  • 374
  • 2
  • 8

1 Answers1

2

ENS (Ethereum Name Service) does not support IPv4 records.

It does support plain text records where you can store any text information including an IPv4 address. But based on other context, that's probably not what you're looking for.

If you open the domain https://james.eth/ in a browser that supports ENS (Brave Browser for example, as well as any mainstream browser with MetaMask or other extension that supports ENS), it shows a website.

This is because the ENS record james.eth resolves to content hash URI ipfs://bafybeihvgxwg4cafjoj4ahzf2ingpvuhaf5odu4i3bk7hnyxvglc7eybrm (source) that links to an IPFS location - which is the actual website index page, the HTML file. Your browser then retrieves the HTML file from an IPFS node - usually through an intermediary service such as https://dweb.link/.

Having said all of that, based on this GitHub issue comment, it seems that content hash resolving is currently (May 2023) not available in web3.py.

So at least here's a working example in web3js for inspiration and possibly you'll be able to find another way in Python how to resolve the record. Unfortunately I'm not a Python developer and can't help more specifically.

const Web3 = require("web3");
const web3 = new Web3("https://eth-mainnet.g.alchemy.com/v2/*********");

web3.eth.ens.getContenthash("james.eth").then((result) => {
    console.log(result);
});

prints out:

{
  protocolType: 'ipfs',
  decoded: 'QmeqrHXXeGuJxeeU4tTh72Gm1pqUaxfU66P224f6wMDvqQ',
  error: null
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • `eth.link` can resolve to ETH names to DNS records, but its dog slow - I wanted to reproduce its functionality using RPC. Does `content hash resolving is currently (May 2023) not available` <- this means what `eth.link` does is not supported in `web3.py` ? – James Stevens May 16 '23 at 10:58
  • also that `getContenthash` isn't going to be supported in `web3.py` :( – James Stevens May 16 '23 at 11:43