Skip to content

Instantly share code, notes, and snippets.

@0xlxy
Created June 2, 2023 04:58
Show Gist options
  • Save 0xlxy/8c5f5ed1540d9a53fce8b2bed4e1ad33 to your computer and use it in GitHub Desktop.
Save 0xlxy/8c5f5ed1540d9a53fce8b2bed4e1ad33 to your computer and use it in GitHub Desktop.
ENS Name Resolver
{
"name": "ens",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ethers": "^6.4.1"
}
}
const { ethers } = require("ethers");
async function lookupENSAddress(ens) {
// Infura provider setup
const network = "mainnet";
const apiKey = "a867fc6179514df5b192178850c9740a";
const provider = new ethers.InfuraProvider(network, apiKey);
try {
// Lookup Address
const ensName = await provider.lookupAddress(ens);
return ensName;
} catch (error) {
console.log("Error occurred while looking up ENS address:", error);
return null;
}
}
// Example usage
const addr = "0xD2Af803ad747ea12Acf5Ae468056703aE48785b5";
lookupENSAddress(addr)
.then((ensName) => {
if (ensName) {
console.log(`ENS name for wallet address ${addr}:`, ensName);
} else {
console.log(`No ENS name found for wallet address ${addr}`);
}
})
.catch((error) => {
console.log("Error occurred:", error);
});
const { ethers } = require("ethers");
async function lookupENSAddress(ens) {
// Infura provider setup
const network = "mainnet";
const apiKey = "";
const provider = new ethers.InfuraProvider(network, apiKey);
try {
// Lookup ENS name
const address = await provider.resolveName(ens);
return address;
} catch (error) {
console.log("Error occurred while looking up ENS address:", error);
return null;
}
}
// Example usage
const ensName = "111.eth";
lookupENSAddress(ensName)
.then((address) => {
if (address) {
console.log(`Wallet address for ENS name ${ensName}:`, address);
} else {
console.log(`No wallet address found for ENS name ${ensName}`);
}
})
.catch((error) => {
console.log("Error occurred:", error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment