The code runs but says "food.eth" is available (it isn't):
var Web3 = require("web3")
let web3 = new Web3(Web3.givenProvider || "ws://localhost:8546");
var ens = web3.eth.ens;
const words = [
'beer',
'food',
'chovy',
];
(async () => {
for (let word of words) {
console.log('checking: '+ word);
const addr = await getDomain(word);
console.log(word+': '+ addr);
}
})();
async function getDomain(word) {
try {
const addr = await ens.getAddress(`${word}.eth`)
console.log(addr);
return addr;
} catch(err) {
console.error(err);
return;
}
}
I'm running geth with the following command on Ubuntu 20.04:
geth --syncmode "light" --ws --mainnet
edit: From what I can tell after reading up, I need a "archive node" to query eth domains. Since the domain may not have been registered in the last 128 blocks (which is what a full node is).
Most of the cloud apis out there don't allow many queries for archive nodes.
edit: So apparently I have to set the resolver for the call to work:
const resolv = await getResolver(word);
await ens.setResolver(`${word}.eth`, resolv);
async function getResolver(word) {
try {
const resolv = await ens.getResolver(`${word}.eth`);
console.log('found resolver: ', resolv._address);
return resolv._address;
} catch(err) {
console.error(err, 'resolver error');
return;
}
}
But now I get this error:
$ node index.js
found resolver: 0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41
(node:426847) UnhandledPromiseRejectionWarning: Error: No "from" address specified in neither the given options, nor the default options.
at Object.ContractNoFromAddressDefinedError (/home/ubuntu/www/eth/node_modules/web3-core-helpers/lib/errors.js:125:16)
at Object._executeMethod (/home/ubuntu/www/eth/node_modules/web3-eth-contract/lib/index.js:772:48)
at /home/ubuntu/www/eth/node_modules/web3-eth-ens/lib/contracts/Registry.js:461:109
at processTicksAndRejections (internal/process/task_queues.js:97:5)