# Get DAO Token Owners

Each DAO is represented by a <mark style="color:yellow;">realm</mark> id. Given a realm address we can fetch all the token owners who are part of that DAO. For this, we need to focus on <mark style="color:yellow;">TokenOwnerRecordV1 and TokenOwnerRecordV2</mark> accounts.

Few fields of our interest are

* <mark style="color:yellow;">governingTokenMint</mark>: Token address which governs the DAO.
* <mark style="color:yellow;">governingTokenDepositAmount</mark>: How much tokens have been deposited by the user.
* <mark style="color:yellow;">governingTokenOwner</mark>: The user who owns the governing token.

You can run this code in <mark style="color:yellow;">replit</mark> to see it in action.

{% tabs %}
{% tab title="Code" %}
{% code overflow="wrap" %}

```javascript
// Node doesn't implement fetch so we have to import it
import fetch from "node-fetch";
const SHYFT_API_KEY = "YOUR-KEY"

async function fetchGraphQL(query, variables = {}, name = "MyQuery") {
  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/?api_key=${SHYFT_API_KEY}`,
    {
      method: "POST",
      body: JSON.stringify({
        query: query,
        variables: variables,
        operationName: name
      })
    }
  );

  return await result.json();
}

async function getRealmsForWallet(wallet) {
  const query = `
    query MyQuery {
      GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV1(
        where: {realm: {_eq: ${JSON.stringify(wallet)}}}
      ) {
        governingTokenDepositAmount
        governingTokenMint
        governingTokenOwner
        pubkey
      }
      GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV2(
        where: {realm: {_eq: ${JSON.stringify(wallet)}}}
      ) {
        governingTokenDepositAmount
        governingTokenMint
        governingTokenOwner
        pubkey
      }
    }
  `;

  const { errors, data } = await fetchGraphQL(query);

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }
  
  // do something great with this precious data
  return data;
}

//Get users for Grape DAO
const daos = await getRealmsForWallet("By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip")

console.dir(daos, {depth: null})
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV2": [
      {
        "governanceDelegate": null,
        "governingTokenDepositAmount": 1000000,
        "governingTokenMint": "8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA",
        "governingTokenOwner": "4NruycWTZFvbaF9wjF9uRVb2wP5gqTZtUpiDZ2GyQDZv",
        "lamports": 2853600,
        "outstandingProposalCount": 0,
        "realm": "By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip",
        "reserved": "\\x000000000000",
        "unrelinquishedVotesCount": 0,
        "version": 0
      }
      // More response items in the array
    ],
    "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV1": [
      {
        "governanceDelegate": null,
        "governingTokenDepositAmount": 0,
        "governingTokenMint": "8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA",
        "governingTokenOwner": "5s4KyZSCExZVRPg579FBTLARtpxteJf9k5UoQpsaPvoz",
        "lamports": 1962720,
        "outstandingProposalCount": 0,
        "realm": "By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip",
        "reserved": "\\x000000000000",
        "unrelinquishedVotesCount": 0,
        "version": 0
      }
      // More response items in the array
    ]
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shyft.to/solana-indexers/case-studies/solana-governance-realms/get-dao-token-owners.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
