You can query contract directly for resolved address, primary name, attributes,...
// Replace with your contract address
const nnsContractAddress = '0x...'
// Create contract instance
const contract = getContract({
address: nnsContractAddress,
abi: contractAbi,
publicClient,
walletClient
})
try {
// Example domain
const normalizedName = normalize('salmo.nad');
const node = namehash(normalizedName);
// 1. Get resolved address for a name
const resolvedAddress = await contract.read.getResolvedAddress([node])
console.log(`Resolved address for ${domain}:`, resolvedAddress)
// 2. Get primary name for an address
const address = '0x1234567890123456789012345678901234567890'
const primaryName = await contract.read.getPrimaryNameForAddress([address])
console.log('Primary name for address:', primaryName)
// 3. Get single name attribute
const attributeKey = 'avatar'
const attributeValue = await contract.read.getNameAttribute([node, attributeKey])
console.log(`Attribute ${attributeKey}:`, attributeValue)
// 4. Get multiple name attributes
const attributeKeys = ['avatar', 'email', 'url']
const attributes = await contract.read.getNameAttributes([node, attributeKeys])
console.log('Multiple attributes:', attributes)
} catch (error) {
console.error('Error:', error)
}
// Setup provider and signer
const provider = new ethers.providers.JsonRpcProvider('YOUR_RPC_URL');
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
const abi = [...]
// Contract setup
const nnsContractAddress = 'YOUR_CONTRACT_ADDRESS';
const contract = new ethers.Contract(nnsContractAddress, abi, provider);
const contractWithSigner = contract.connect(signer);
try {
// Example values
const domain = 'example.nad';
const node = namehash(domain);
const address = '0x1234567890123456789012345678901234567890';
// Read queries
// 1. Get resolved address
const resolvedAddress = await contract.getResolvedAddress(node);
console.log(`Resolved address for ${domain}:`, resolvedAddress);
// 2. Get primary name for address
const primaryName = await contract.getPrimaryNameForAddress(address);
console.log('Primary name for address:', primaryName);
// 3. Get single attribute
const avatarValue = await contract.getNameAttribute(node, 'avatar');
console.log('Avatar value:', avatarValue);
// 4. Get multiple attributes
const attributeKeys = ['avatar', 'email', 'url'];
const attributes = await contract.getNameAttributes(node, attributeKeys);
console.log('Multiple attributes:', attributes);
} catch (error) {
console.error('Error:', error);
}