Get the wallet address from an ENS domain name
2 min read
Python script retrieving the wallet address from an
ENS domain name. In this example we're going to use the
web3.py library. Let's go!
I just want the code
OK, if you just want the code, grab it here or 👇
from web3 import Web3 from ens import ENS rpc_url = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161" # The provider is your connection to a blockchain web3 = Web3(Web3.HTTPProvider(rpc_url)) #log if we're connected or not print(web3.isConnected()) ns = ENS.fromWeb3(web3) print(ns.address(input("enter your ens domain to get your wallet address\n")))
All you need for this script is a virtual environment and the
To fire up a virtual environment:
python -m env ./myv
and to activate the environment:
Then go ahead and install the
pip install web3
Finally create a
Python file to code your program:
There are only 7 lines of code and I probably could've done it in 5 😶....just saying.
OK, let's import the packages. Note there are 2 packages, but we don't need a separate pip install for the second one.
from web3 import Web3 from ens import ENS
Setup an RPC URL to define which blockchain we want to target and which node provider we want to use. Here I'm picking the
Ethereum Mainnet and I'm using an
rpc_url = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
Now let's establish our connection:
web3 = Web3(Web3.HTTPProvider(rpc_url))
We can check with the following line if we're connected properly:
Almost done. We instantiate an object
ns and get access to all the methods inside the
ns = ENS.fromWeb3(web3)
Finally we can use the
address method to retrieve the wallet address from an
ENS domain. Over here we ask the user to enter their
ENS domain and then the program returns the wallet address.
print(ns.address(input("enter your ens domain to get your wallet address\n")))
There you have it. A simple
Python program to get the wallet address from an
ENS domain. This library has a ton more methods. I'll be sharing some other scripts, but you can check out the web3.py docs for more info!