Query contract directly

You can query contract directly for resolved address, primary name, attributes,...

Method
Return

getResolvedAddress

Resolved address for a name

getResolvedAddresses

Resolved addresses for a list of name

getPrimaryNameForAddress

Primary name for an address (Without TLD .nad)

getPrimaryNameForAddresses

Primary names for a list of address (Without TLD .nad)

getNameAttribute

An attribute associated with a name

getNameAttributes

Attributes associated with a name

getProfileForAddress

Return a profile for a wallet address, including primary name, avatar, ...

getProfilesForAddresses

Return profiles for a list of wallet address, including primary name, avatar, ...

For more information about contract address and ABI, checkout Contracts

Example:

Viem:

// 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)
  }

Ethersjs:

// 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);
  }

Last updated