Query contract directly
Method
Return
// 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)
}Pros & Cons
β
Pro
β οΈ Cons
Last updated