Skip to content

Instantly share code, notes, and snippets.

@nxt3d
Last active March 29, 2023 15:54
Show Gist options
  • Save nxt3d/262bf31935f7341b6162700a702c1383 to your computer and use it in GitHub Desktop.
Save nxt3d/262bf31935f7341b6162700a702c1383 to your computer and use it in GitHub Desktop.
Resolve XAP names
import { config } from 'dotenv';
import { ethers } from 'ethers';
import axios from 'axios';
config();
// Goerli XAP resolver contract address
const contractAddr = "0x520497595f742426708dfbDcaB9D0D7D8555D937"
// Fetch the contract ABI from Etherscan
async function fetchContractAbi(contractAddress) {
const url = `https://api-goerli.etherscan.io/api?module=contract&action=getabi&address=${contractAddress}&apikey=${process.env.ETHERSCAN_API_KEY}`;
try {
const response = await axios.get(url);
const abi = JSON.parse(response.data.result);
return abi;
} catch (error) {
console.error(`Error fetching contract ABI: ${error.message}`);
return null;
}
}
// Main function to call the contract function
async function main() {
try {
// Fetch the contract ABI
const contractAbi = await fetchContractAbi(contractAddr);
if (!contractAbi) {
console.error('Failed to fetch contract ABI. Exiting...');
return;
}
// Connect to the Ethereum network using the JSON-RPC URL
const provider = new ethers.JsonRpcProvider(process.env.API_URL);
// Connect to the contract using the provider
const contract = new ethers.Contract(contractAddr, contractAbi, provider);
// -------------------------- everything is set up -------------------------- //
var resolver = await provider.getResolver("addr-123.xap22.eth");
console.log(await resolver.getAddress(60))
// Call the function with the provided arguments
const result1 = await contract.resolve('0x08616464722d3132330578617032320365746800','0xf1cb7e060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c')
console.log(`Result: ${result1}`);
var resolverARB1 = await provider.getResolver("arb1-123.xap22.eth");
console.log(await resolverARB1.getAddress(2147525809))
// Call the function with the provided arguments
const result2 = await contract.resolve('0x08617262312d3132330578617032320365746800','0xf1cb7e060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000A4B1')
console.log(`Result: ${result2}`);
} catch (error) {
console.error(`Error: ${error.message}`);
}
}
// Call the main function
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment