# Get Proposals For Governing Mint

Each DOA is governed by certain tokens. In order to vote on proposals for a DAO, you need to have those tokens.  To get this data we need to query&#x20;

* **GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw\_ProposalV1**
* **GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw\_ProposalV2**

and filter the data based on the <mark style="color:yellow;">governingTokenMint.</mark>

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

{% tabs %}
{% tab title="Code" %}

```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 fetchProposals(mint) {

const query = `
  query MyQuery {
    GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
      where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}}
    ) {
      closedAt
      descriptionLink
      draftAt
      executingAt
      executionFlags
      governance
      governingTokenMint
      instructionsCount
      instructionsExecutedCount
      instructionsNextIndex
      lamports
      maxVoteWeight
      name
      noVotesCount
      signatoriesCount
      signatoriesSignedOffCount
      signingOffAt
      state
      tokenOwnerRecord
      voteThreshold
      votingAt
      votingAtSlot
      votingCompletedAt
      yesVotesCount
    }
    GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(
      where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}}
    ) {
      abstainVoteWeight
      closedAt
      denyVoteWeight
      descriptionLink
      draftAt
      executingAt
      executionFlags
      governance
      governingTokenMint
      lamports
      maxVoteWeight
      maxVotingTime
      name
      options
      reserved1
      signatoriesCount
      signatoriesSignedOffCount
      signingOffAt
      startVotingAt
      state
      tokenOwnerRecord
      vetoVoteWeight
      voteThreshold
      voteType
      votingAt
      votingAtSlot
      votingCompletedAt
    }
  }
`;

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

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }

  // do something great with this precious data
  console.log(data);
}
//Fetch all proposals for Grape governing token
fetchProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
```

{% endtab %}
{% endtabs %}

#### Fetch Active Proposals

Each proposals goes though different <mark style="color:yellow;">states</mark> which you can read more about [<mark style="color:red;">here</mark>](https://github.com/solana-labs/solana-program-library/blob/master/governance/README.md#proposal-accounts). We are interested in active proposals, which means we need all proposals where state equals to 2. We will modify the above example to account for it.

{% 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 fetchActiveProposals(mint) {

const query = `
  query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
    where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}, state: {_eq: 2}}
  ) {
    closedAt
    descriptionLink
    draftAt
    executingAt
    executionFlags
    governance
    governingTokenMint
    instructionsCount
    instructionsExecutedCount
    instructionsNextIndex
    lamports
    maxVoteWeight
    name
    noVotesCount
    signatoriesCount
    signatoriesSignedOffCount
    signingOffAt
    state
    tokenOwnerRecord
    voteThreshold
    votingAt
    votingAtSlot
    votingCompletedAt
    yesVotesCount
  }
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(
    where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}, state: {_eq: 2}}
  ) {
    abstainVoteWeight
    closedAt
    denyVoteWeight
    descriptionLink
    draftAt
    executingAt
    executionFlags
    governance
    governingTokenMint
    lamports
    maxVoteWeight
    maxVotingTime
    name
    options
    reserved1
    signatoriesCount
    signatoriesSignedOffCount
    signingOffAt
    startVotingAt
    state
    tokenOwnerRecord
    vetoVoteWeight
    voteThreshold
    voteType
    votingAt
    votingAtSlot
    votingCompletedAt
  }
}`;

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

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }

  // do something great with this precious data
  console.log(data);
}

//Fetch active proposals for Grape governing token
fetchActiveProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
```

{% endcode %}

#### Get all proposals sorted by voting time

Each proposal has a <mark style="color:yellow;">votingAt</mark> timestamp, which tells you when voting started for that proposal. While fetching proposals, we can order them by votingAt to see new proposals first.

```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 fetchActiveProposals(mint) {

const query = `
  query MyQuery {
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
    where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}
    order_by: {votingAt: desc}
  ) {
    closedAt
    descriptionLink
    draftAt
    executingAt
    executionFlags
    governance
    governingTokenMint
    instructionsCount
    instructionsExecutedCount
    instructionsNextIndex
    lamports
    maxVoteWeight
    name
    noVotesCount
    signatoriesCount
    signatoriesSignedOffCount
    signingOffAt
    state
    tokenOwnerRecord
    voteThreshold
    votingAt
    votingAtSlot
    votingCompletedAt
    yesVotesCount
  }
  GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(
    where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}
    order_by: {votingAt: desc}
  ) {
    abstainVoteWeight
    closedAt
    denyVoteWeight
    descriptionLink
    draftAt
    executingAt
    executionFlags
    governance
    governingTokenMint
    lamports
    maxVoteWeight
    maxVotingTime
    name
    options
    reserved1
    signatoriesCount
    signatoriesSignedOffCount
    signingOffAt
    startVotingAt
    state
    tokenOwnerRecord
    vetoVoteWeight
    voteThreshold
    voteType
    votingAt
    votingAtSlot
    votingCompletedAt
  }
}`;

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

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }

  // do something great with this precious data
  console.log(data);
}

//Fetch active proposals for Grape governing token
fetchActiveProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
```
