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)