Shyft
Start BuildingSupportWebsite
  • Welcome
    • 👋Introducing Shyft
    • 🏗️Start Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚡gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • 📔Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • 🔥Pause a callback
      • 🔥Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • 📀Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • 🔥Pumpswap
        • 🔥Get Pool by Address
        • 🔥Get Pool by Creator Address
        • 🔥Get Pools by Token Addresses
      • 🔥Raydium Launchpad
        • 🔥Get Bonding Curve Details by Pool Address
        • 🔥Get All Pools for a Creator
        • 🔥Get Pools by Token Addresses
        • 🔥Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • 🔥Create Gasless
      • Create
      • Read All
      • Burn
      • 🔥Burn Multiple NFTs V2
      • Update
      • 🔥Create NFT from Metadata
      • 🔥Read Wallet Nfts
      • 🔥Read Selected NFTs
      • 🔥Get NFT Owners
      • 🔥Update NFT Metadata Uri
      • 🔥Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • 🔥Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page

Was this helpful?

  1. Solana Super Indexers
  2. Case Studies
  3. Tensor

Get all Bids of a Collection

Getting all bids of on NFTs belonging to a specific 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 target and targetId.

  • If target object has key assetId, then targetId points to an actual cNFT address.

  • If target object has key whitelist, then targetId points to the collection detail. (coming soon)

In this example we are checking for {target: {_has_key: "assetId"}. We will have to compare targetId 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 _in filter which checks if targetId is present in the mint list.

Active Bids on a cNFT Collection (Compressed NFT collection)

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;
}

{
  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
    }
  ]
}

We can also also query the same for Non-compressed NFTs of a collection. However, this data is available in the bidState account of Tensor_Bid account. We can fetch all the NFTs belonging to a particular collection using DAS, and then use the where filter on the nftMint to get the desired result. An example is illustrated below.

We can use the _in check to to compare if a key exists in a range(array) of values

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

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;
}
{ //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'
    }
  ]
}
PreviousGet Active Listings of a CollectionNextGet all Pools of a Margin Account

Last updated 1 year ago

Was this helpful?

📀