> For the complete documentation index, see [llms.txt](https://docs.nad.domains/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nad.domains/developers/integrating-into-your-dapps/query-contract-directly.md).

# Query contract directly

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

<table><thead><tr><th width="260.8515625">Method</th><th>Return</th></tr></thead><tbody><tr><td>getResolvedAddress</td><td>Resolved address for a name</td></tr><tr><td>getResolvedAddresses</td><td>Resolved addresses for a list of name</td></tr><tr><td>getPrimaryNameForAddress</td><td>Primary name for an address (Without TLD <code>.nad</code>)</td></tr><tr><td>getPrimaryNameForAddresses</td><td>Primary names for a list of address (Without TLD <code>.nad</code>)</td></tr><tr><td>getNameAttribute</td><td>An attribute associated with a name</td></tr><tr><td>getNameAttributes</td><td>Attributes associated with a name</td></tr><tr><td>getProfileForAddress</td><td>Return a profile for a wallet address, including primary name, avatar, ...</td></tr><tr><td>getProfilesForAddresses</td><td>Return profiles for a list of wallet address, including primary name, avatar, ...</td></tr><tr><td></td><td></td></tr></tbody></table>

For more information about contract address and ABI, checkout [Contracts](/developers/contracts.md)

Example:

`Viem:`

```typescript
// 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:

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

## Pros & Cons

### ✅ Pro

* **You are in full control**
* **Minimal dependencies**: only requires blockchain client, ABI, and custom name processing.
* **Immediate access** to all on-chain data if you manage smart-contract permissions and upgrades.
* **Decentralized**: No reliance on external APIs or services

### ⚠️ Cons

* **Manual name processing**: you must normalize and compute namehash yourself for each query.
* **Boilerplate code**: constructing contract instances and handling RPC logic manually.
* **Verbosity & error-prone**: more setup work, especially for batch queries.
* **Maintenance Burden**: Need to track contract updates and ABI changes
