# Get all Bids of a Collection

To query active bids of a collection, we will have to query data differently for Tensor cNFT and normal NFTs.

For Tensor cNFT, we have to check two fields <mark style="color:yellow;">target</mark> and <mark style="color:yellow;">targetId</mark>.

* If <mark style="color:yellow;">target</mark> object has key <mark style="color:yellow;">assetId</mark>, then <mark style="color:yellow;">targetId</mark> points to an actual cNFT address.
* If <mark style="color:yellow;">target</mark> object has key <mark style="color:yellow;">whitelist</mark>, then <mark style="color:yellow;">targetId</mark> points to the collection detail. (coming soon)

In this example we are checking for <mark style="color:yellow;">{target: {\_has\_key: "assetId"}.</mark> We will have to compare <mark style="color:yellow;">targetId</mark> against a pre defined collection mint list, which we can save before hand or fetch through DAS. For this example, we will be fetching through a DAS call.

The key is to use GraphQL <mark style="color:yellow;">\_in</mark> filter which checks if targetId is present in the mint list.

#### Active Bids on a cNFT Collection (Compressed NFT collection)

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

```typescript
import { gql, GraphQLClient } from "graphql-request";
import { Network, ShyftSdk } from '@shyft-to/js';

const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
});

const shyft = new ShyftSdk({ apiKey: YOUR-KEY, network: Network.Mainnet }); //Initialize Shyft SDK to use DAS

async function getAllBidsFromCollection(collectionAddr:string) {

    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr);
    // all fields can be cherry-picked as per your requirement
    const query = gql`
      query MyQuery {
        TENSOR_CNFT_bidState(
          where: {target: {_has_key: "assetId"}, targetId: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
        ) {
          targetId
          target
          bidId
          owner
          cosigner
          currency
          makerBroker
          rentPayer
          pubkey
          amount
        }
      }
    `;

  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}

getAllBidsFromCollection('AGSmrgdkkwYRpvWXZ2kf4KoPdG5jPMj8KrNjnAgsum54')
//replace with your NFT collection address

async function getAllMintsofColl(collectionAddr:string) { //get all NFTs from a specific collection
    let page = 1;
    const assets = [];

    while (page > 0) {
      const assetsByGroup = await shyft.rpc.getAssetsByGroup({
        groupKey: 'collection',
        groupValue: collectionAddr,
        page,
        limit: 1000,
      });

      assets.push(...assetsByGroup.items);
      page = assetsByGroup.total !== 1000 ? -1 : page + 1;
    }

    console.log('Total NFT ', assets.length);
    const nftAddresses = assets.map((nft) => nft.id);
    return nftAddresses;
}


```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  TENSOR_CNFT_bidState: [
    {
      targetId: 'J6CgUcc8HwXKLai9fg2Vd1z66VBEQuPQBJbxJ6nGKwvr',
      target: { assetId: {} },
      bidId: 'J6CgUcc8HwXKLai9fg2Vd1z66VBEQuPQBJbxJ6nGKwvr',
      owner: '2BxjCgpiXfZLdGhy3KHhCoT55xTysCuRjaQNWQh8zcTH',
      cosigner: '11111111111111111111111111111111',
      rentPayer: '2BxjCgpiXfZLdGhy3KHhCoT55xTysCuRjaQNWQh8zcTH',
      pubkey: 'GMztFGoFxTdjfx85phhRBYYUtPKvZSx5zadvFx2yeexE',
      amount: 5000
    },
    {
      targetId: 'HGQhiit8tfyaWCLoB39aDigkmP2iGwdTtEnLZcqeuCQx',
      target: { assetId: {} },
      bidId: 'HGQhiit8tfyaWCLoB39aDigkmP2iGwdTtEnLZcqeuCQx',
      owner: '2BxjCgpiXfZLdGhy3KHhCoT55xTysCuRjaQNWQh8zcTH',
      cosigner: '11111111111111111111111111111111',
      rentPayer: '2BxjCgpiXfZLdGhy3KHhCoT55xTysCuRjaQNWQh8zcTH',
      pubkey: 'BsaMdK95XFrMnjciXtxQ4atZaajq3obgmfb1gzdeSUCD',
      amount: 5000
    },
    {
      targetId: 'J6CgUcc8HwXKLai9fg2Vd1z66VBEQuPQBJbxJ6nGKwvr',
      target: { assetId: {} },
      bidId: 'J6CgUcc8HwXKLai9fg2Vd1z66VBEQuPQBJbxJ6nGKwvr',
      owner: 'BDtwL5Yo98QHVT15fgMFd7tMXAGUH7aEqAMMTkRhHme',
      cosigner: '11111111111111111111111111111111',
      rentPayer: 'BDtwL5Yo98QHVT15fgMFd7tMXAGUH7aEqAMMTkRhHme',
      pubkey: 'GdKPnX9pV67qsQ9LD5YXWTcFQfarU8uCGHQWQ2VaG5aZ',
      amount: 20000
    }
  ]
}
```

{% endtab %}
{% endtabs %}

We can also also query the same for Non-compressed NFTs of a collection. However, this data is available in the <mark style="color:yellow;">bidState</mark> account of <mark style="color:yellow;">Tensor\_Bid</mark> account. We can fetch all the <mark style="color:yellow;">NFTs</mark> belonging to a particular <mark style="color:yellow;">collection</mark> using DAS, and then  use the <mark style="color:yellow;">where</mark> filter on the nftMint to get the desired result. An example is illustrated below.

{% hint style="info" %}
We can use the <mark style="color:yellow;">\_in</mark> check to to compare if a key exists in a range(array) of values
{% endhint %}

#### Active Bids on a NFT Collection (Non-Compressed NFT collection)

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

```typescript
import { gql, GraphQLClient } from "graphql-request";
import { Network, ShyftSdk } from '@shyft-to/js';

const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=YOUR-KEY`;

const graphQLClient = new GraphQLClient(endpoint, {
  method: `POST`,
  jsonSerializer: {
    parse: JSON.parse,
    stringify: JSON.stringify,
  },
});

const shyft = new ShyftSdk({ apiKey: YOUR-KEY, network: Network.Mainnet }); //Initialize Shyft SDK to use DAS

async function getAllBidsFromCollection(collectionAddr:string) {
    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr);
    // all fields can be cherry-picked as per your requirement
    const query = gql`
    query MyQuery {
      tensor_bid_BidState(
        where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}
      ) {
        bidAmount
        bidder
        expiry
        nftMint
        pubkey
      }
    }
    `;
  const response = await graphQLClient.request(query);
  console.dir(response,{depth: null});
  
}

getAllBidsFromCollection('6qxgQKV5pj4Jg4sGU7AvM2xeFwVwfGdJmXj889AyKQqu')
//replace with your NFT collection address

async function getAllMintsofColl(collectionAddr:string) { //get all NFTs from a specific collection
    let page = 1;
    const assets = [];

    while (page > 0) {
      const assetsByGroup = await shyft.rpc.getAssetsByGroup({
        groupKey: 'collection',
        groupValue: collectionAddr,
        page,
        limit: 1000,
      });

      assets.push(...assetsByGroup.items);
      page = assetsByGroup.total !== 1000 ? -1 : page + 1;
    }

    console.log('Total NFT ', assets.length);
    const nftAddresses = assets.map((nft) => nft.id);
    return nftAddresses;
}
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{ //response shortened
  "tensor_bid_BidState": [
    {
      "bidAmount": 1781000000,
      "bidder": '9k6EZau26m4fft4WodqyAetGALaEbunPcHMWv8CALzEe',
      "expiry": 1735040415,
      "nftMint": 'BRzduX8KtT5Q6jPnVC9gdL7QCAB3KJDq8T1VaunACfL7',
      "pubkey": '6KWQRqLG4jsXjy4PZ771rsD6gnNwFqVKC1YSR58RTkdX'
    },
    {
      "bidAmount": 1110000000,
      "bidder": '9k6EZau26m4fft4WodqyAetGALaEbunPcHMWv8CALzEe',
      "expiry": 1731985375,
      "nftMint": 'B2h697DzabcRAhsWEu8mRfJn7uyoLThRu2fijiyeHyUi',
      "pubkey": 'E3SjYuESb26iEHBcpUryLiJ1HXDBQ9K4VawGwvmgM69J'
    },
    {
      "bidAmount": 1110000000,
      "bidder": '9k6EZau26m4fft4WodqyAetGALaEbunPcHMWv8CALzEe',
      "expiry": 1731985600,
      "nftMint": 'CvRCq747QqFS5HV6ZgVG1jgTvbZbxpbSc4prYVK5DJYR',
      "pubkey": 'JcmyvcBJxAfiUt745SwMisfwoa8KFneqyvMM2canLtm'
    },
    {
      "bidAmount": 1110000000,
      "bidder": '9k6EZau26m4fft4WodqyAetGALaEbunPcHMWv8CALzEe',
      "expiry": 1731985600,
      "nftMint": 'FNsQrdJwSToY1i5agNSU9YSEVmvcCfwp7zxXLZRR1nQu',
      "pubkey": 'F1vRUZ71XpN98nQTY3MU1aFeCaWTAsETLsHQcxvqdH7s'
    },
    {
      "bidAmount": 2280000000,
      "bidder": '9k6EZau26m4fft4WodqyAetGALaEbunPcHMWv8CALzEe',
      "expiry": 1734999177,
      "nftMint": 'GFoX6GMg8ZmQuoye6aJtjyS3uG3zvmXZ9k62NR1JdBbd',
      "pubkey": 'dgW1nms9CTnSSsikiDx3Ww3Ai1R7m1449VNicuA1Ai6'
    }
  ]
}
```

{% 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/tensor/get-all-bids-of-a-collection.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.
