Get Active Bids of a Wallet

Illustrates how we can get active NFT Bids for a single wallet on Tensor using GraphQl

In the Tensor marketplace, users can bid on both NFTs and cNFTs. Tensor has two different programs that keep track of these bids.

  • The bids on cNFTs are managed and stored in the bidState account of the Tensor_CNFT program

  • The bids on NFTs are handled by the bidState account of the Tensor_bid program.

Cross program query is possible here. You can query both programs in a single graphQl call.

With SHYFT’s SuperIndexer we can query both of these programs in a single query, while also applying the where filter on the bidder field of the bidState field of Tensor_bid program and the owner field of the Tensor_CNFT program . This would give us all the bids by one particular bidder wallet.

The target field of the Tensor_CNFT program can have two possible keys, assetId and whitelist. 'assetId' indicates the bid is on a single NFT, and 'whitelist' indicates the bid is on a whitelist account equivalent to a collection.

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();

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

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();

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

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();

Last updated