# Get Active Bids of a Wallet

In the Tensor marketplace, users can bid on <mark style="color:yellow;">both</mark> NFTs and cNFTs. Tensor has two different programs that keep track of these bids.

* The bids on cNFTs are managed and stored in the <mark style="color:yellow;">bidState</mark> account of the <mark style="color:yellow;">Tensor\_CNFT</mark> program
* The bids on NFTs are handled by the <mark style="color:yellow;">bidState</mark> account of the <mark style="color:yellow;">Tensor\_bid</mark> program.

{% hint style="success" %}
Cross program query is possible here. You can query both programs in a single graphQl call.
{% endhint %}

With SHYFT’s SuperIndexer we can <mark style="color:yellow;">query both</mark> of these programs <mark style="color:yellow;">in a single query</mark>, while also applying the *where* filter on the bidder field of the *<mark style="color:yellow;">bidState</mark>* field of *Tensor\_bid* program and the *<mark style="color:yellow;">owner</mark>* field of the *Tensor\_CNFT* program . This would give us all the bids by one particular bidder wallet.

{% hint style="info" %}
The *<mark style="color:yellow;">target</mark>* field of the Tensor\_CNFT program can have two possible keys, *<mark style="color:yellow;">assetId</mark>* and *<mark style="color:yellow;">whitelist</mark>. 'assetId'* indicates the bid is on a single NFT, and *'whitelist'* indicates the bid is on a whitelist account equivalent to a collection.
{% endhint %}

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

```javascript
async function fetchGraphQL(operationsDoc, operationName, variables) {
  const result = await fetch(
    "https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY&network=mainnet-beta",
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: variables,
        operationName: operationName
      })
    }
  );

  return await result.json();
}

const bidder = "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F";
//enter bidder wallet address for which you want to fetch bids

const operationsDoc = `
  query MyQuery {
    tensor_bid_BidState(
      where: {bidder: {_eq: ${JSON.stringify(bidder)}}
    ) {
      bidAmount
      bidder
      expiry
      nftMint
      pubkey
    }
    TENSOR_CNFT_bidState(
      where: {target: {_has_key: "assetId"}, owner: {_eq: ${JSON.stringify(bidder)}}}
    ) {
      target
      targetId
      owner
      pubkey
      expiry
      currency
      bidId
      amount
    }
  }
`;
//querying both programs in gQl call
function fetchMyQuery() {
  return fetchGraphQL(
    operationsDoc,
    "MyQuery",
    {}
  );
}

async function startFetchMyQuery() {
  const { errors, data } = await fetchMyQuery();

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

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

startFetchMyQuery();
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{ //response shortened for visibility
  "data": {
    "tensor_bid_BidState": [
      {
        "bidAmount": 1500000000,
        "bidder": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "expiry": 1740103769,
        "nftMint": "tpLApHuN2pwyAJd2bByxTsitzXWL5LaH5YqwFZMx1Kt",
        "pubkey": "6tJFEvJtgbBpoWCovwH291vWGA14Je1Baja5i4xyR5Fj"
      },
      {
        "bidAmount": 200000000,
        "bidder": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "expiry": 1714172253,
        "nftMint": "7zdU6BZVZCSfGKPSs2LwXYMqKzodrmxFJeZG85qyHjf2",
        "pubkey": "4wijcue36SGQ8bLyB2j3ZqdigN5mEvT8PV8tfJfLk3uE"
      }
    ],
    "TENSOR_CNFT_bidState": [
      {
        "target": {
            "assetId": {}
      },
        "targetId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
        "owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "pubkey": "GaEU91W1WJ5diBvBbP4XWBuGnfGTduQkpi9F7VsAzbGH",
        "expiry": 1740553188,
        "currency": null,
        "bidId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
        "amount": 2250000000
      },
      {
        "target": {
          "assetId": {}
      },
        "targetId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
        "owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "pubkey": "QgmyTZLWLYmLLTncyZiVfkjRhcmymPHoXavTqr6H9ka",
        "expiry": 1740519924,
        "currency": null,
        "bidId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
        "amount": 10000000
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

#### Active bids for a wallet on Tensor Bid (Non-compressed NFTs)

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

```javascript
async function fetchGraphQL(operationsDoc, operationName, variables) {
  const result = await fetch(
    "https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY&network=mainnet-beta",
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: variables,
        operationName: operationName
      })
    }
  );

  return await result.json();
}

const operationsDoc = `
  query MyQuery {
    tensor_bid_BidState(
      where: {bidder: {_eq: "12LtD1mjCoo3G79rmq9N98Zgmq4qatwcMAxt1VnJrD8o"}}
    ) {
      bidAmount
      bidder
      expiry
      nftMint
      pubkey
    }
  }
`;

function fetchMyQuery() {
  return fetchGraphQL(
    operationsDoc,
    "MyQuery",
    {}
  );
}

async function startFetchMyQuery() {
  const { errors, data } = await fetchMyQuery();

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

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

startFetchMyQuery();
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  "data": {
    "tensor_bid_BidState": [
      {
        "bidAmount": 1500000000,
        "bidder": "12LtD1mjCoo3G79rmq9N98Zgmq4qatwcMAxt1VnJrD8o",
        "expiry": 1739712261,
        "nftMint": "6hu69KxxXNATFFv5RScJVNu1AMLmBXdFSVGqjsKrdD78",
        "pubkey": "AuqeTsxV5p4RHnsBPyzgZkT3XR24srjiGzbvkifQxdnf"
      },
      {
        "bidAmount": 137000000,
        "bidder": "12LtD1mjCoo3G79rmq9N98Zgmq4qatwcMAxt1VnJrD8o",
        "expiry": 1739775972,
        "nftMint": "DVhpDyG8nT8J5Q5XAUkf8Sj5pJHt2a6DCS8tLP1ZfaQG",
        "pubkey": "Etw93NNH4bHh2ChhygVP3w5HTocPLJWnc73BNTECFUGu"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

#### Active bids for a wallet on Tensor CNFTs (Compressed NFTs)

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

```javascript
async function fetchGraphQL(operationsDoc, operationName, variables) {
  const result = await fetch(
    "https://programs.shyft.to/v0/graphql?api_key=YOUR-API-KEY&network=mainnet-beta",
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: variables,
        operationName: operationName
      })
    }
  );

  return await result.json();
}

const operationsDoc = `
  query MyQuery {
    TENSOR_CNFT_bidState(
      where: {target: {_has_key: "assetId"}, owner: {_eq: "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F"}}
    ) {
      target
      targetId
      owner
      pubkey
      expiry
      currency
      bidId
      amount
    }
  }
`;

function fetchMyQuery() {
  return fetchGraphQL(
    operationsDoc,
    "MyQuery",
    {}
  );
}

async function startFetchMyQuery() {
  const { errors, data } = await fetchMyQuery();

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

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

startFetchMyQuery();
```

{% endtab %}

{% tab title="Response" %}

```json
{ //response shortened
  "data": {
    "TENSOR_CNFT_bidState": [
      {
        "target": {
            "assetId": {}
      },
        "targetId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
        "owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "pubkey": "GaEU91W1WJ5diBvBbP4XWBuGnfGTduQkpi9F7VsAzbGH",
        "expiry": 1740553188,
        "currency": null,
        "bidId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
        "amount": 2250000000
      },
      {
        "target": {
          "assetId": {}
      },
        "targetId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
        "owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
        "pubkey": "QgmyTZLWLYmLLTncyZiVfkjRhcmymPHoXavTqr6H9ka",
        "expiry": 1740519924,
        "currency": null,
        "bidId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
        "amount": 10000000
      }
    ]
  }
}
```

{% 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-active-bids-of-a-wallet.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.
