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 Active Listings of a Collection

Get active listings for a collection on Tensor using GraphQL.

PreviousGet Active Bids of a WalletNextGet all Bids of a Collection

Last updated 1 year ago

Was this helpful?

To query active listings of a collection, we will need to check all listing accounts and see if the listed NFT/cNFT belongs to a pre-defined collection mint list. First thing is to have a mint list of the collection you are interested in. For the sake of this example we will use a DAS call to fetch it.

You can also use our tool to get a collection's mint list.

For Tensor cNFT, we will be checking for assetId field. For Tensor Swap program we will be using nftMint field.

The key is to use GraphQL _in filter which checks if the NFT address is present in the mint list.

Active listings of a collection from Tensor cNFT

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 getAllListFromCollection(collectionAddr:string) {

    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr); //getting all NFT mints from a collection
    
    const query = gql`
      query MyQuery {
        TENSOR_CNFT_listState(where: {assetId: {_in: ${JSON.stringify(allNftMintsforCollection)}}}) {
          rentPayer
          pubkey
          owner
          assetId
          amount
        }
      }
    `;

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

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

getAllListFromCollection('8Hbfu77utvPYTU3ngHis81nnomFW9tQj2yC54EH9B9Q9')
//replace with your NFT collection address
{
    TENSOR_CNFT_listState: [
      {
        rentPayer: '82CUQbRjC2XAcwGumAPDtdzTvYTJ1bpNdMHXTjiDXea',
        pubkey: '79ZwK3dqpGN9MMEFz4srdWhrh2M1QDcF2KdC6sGvSRdH',
        owner: '82CUQbRjC2XAcwGumAPDtdzTvYTJ1bpNdMHXTjiDXea',
        assetId: 'CHCd7ThcHoTE12nerNgwow1azhULh2ZchXSxSTCzBeBH',
        amount: 300000000
      },
      {
        rentPayer: 'DCcUCSp9GAB5D1i6EXNciDie9sDFuuVpn4UwrFbR7V8m',
        pubkey: '7GUKcbY1osAm6irYBtDP3otNb34egYoEcYU7TAGDXJeH',
        owner: 'DCcUCSp9GAB5D1i6EXNciDie9sDFuuVpn4UwrFbR7V8m',
        assetId: '3dDMC6BNUDuvKBffgWgKAXgtaDrpxn2FqCYFVn6VFh2i',
        amount: 340000000
      },
      {
        rentPayer: 'En9ji95Pn6WLu2WWZJKcweN6NpAA2r9ckN8yjPoDAvAJ',
        pubkey: '3sHBCmhwiiiFyVZ46xy3PBxBmPmXMAcQWaJUXiA3cf7i',
        owner: 'En9ji95Pn6WLu2WWZJKcweN6NpAA2r9ckN8yjPoDAvAJ',
        assetId: 'CtAbEwu2cqYTev7vNozHVxauPwYvLCoTBY5b8es54mVz',
        amount: 350000000
      },
      {
        rentPayer: 'FBZzrBUk5hXiHWpCRcquR1fD13ug9XTxPtf99yd2MF25',
        pubkey: '2447Xn14pe8KEbCNQMnmN6HZtrBMSemvSV14Sp5ZVTfu',
        owner: 'FBZzrBUk5hXiHWpCRcquR1fD13ug9XTxPtf99yd2MF25',
        assetId: 'BADdShUsP64nBpiDNFtooTECL3ky91CAsD9FV59yDcHT',
        amount: 320000000
      }
    ]
}

Active Listings of a collection from Tensor Swap (normal NFTs)

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 getAllListFromCollection(collectionAddr:string) {

    const allNftMintsforCollection = await getAllMintsofColl(collectionAddr); //getting all NFT mints from a collection
    
    const query = gql`
      query MyQuery {
        Tensor_SingleListing(where: {nftMint: {_in: ${JSON.stringify(allNftMintsforCollection)}}}) {
          nftMint
          owner
          price
          pubkey
        }
      }
    `;

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

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

//MadLads NFT collection
getAllListFromCollection('J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w')
{
  Tensor_SingleListing: [
    {
      nftMint: 'HAArUyS59aBoHWB5XPap4uauJtqwxHn2ZMqLdViyFKj6',
      owner: 'HBFxRkcjB6MTazJFSgNKXLG2mzDW9EUoeKtpNRrhWhVD',
      price: 160800000000,
      pubkey: '7gQ9HNk2NcGgn2z7spMjYUNrB5JPyRHNAZtqFfMjhrE7'
    },
    {
      nftMint: 'J4oaV9XiH4eqLaoMYBGjbw6LhXbinwakNpdR9JTMMXYr',
      owner: 'DFzWH1SUCnQv6Lq9Dxc5kh5iKztxkzhfCWSYMKfsqTzq',
      price: 196000000000,
      pubkey: 'CuJNbJNVdG4pKjiUafpLx2VtqFWdw6bPAd5o3uDDDeqk'
    },
    {
      nftMint: 'JBfGGLQ7rW9x8tfs5R4Ta9ZRBU2oxKKBSv9tD6eWvWkV',
      owner: 'DkFw7SDw7TpNrpDDbetvNoAfRbjaxJEYLV62fgLbz55M',
      price: 173700000000,
      pubkey: '659WrEpDGH4RzheAqVyZJWjpbomPgsDkTGCXNhrfpziK'
    },
    {
      nftMint: 'HeEJ7jHBynTjfNmouMsCEx6drbBsgrdYrfKbeaCjsUNc',
      owner: 'CYXPrpHMiRvUoAZzQHgth17Lb7LEbj8nh9zfrXqa3FDM',
      price: 160540000000,
      pubkey: '5uhgb9yW7P5XRDZhoSGuTkJHqdnpxHyNiD77X5SjWeEG'
    },
    {
      nftMint: 'J5Dai1wD7sMhMw8bY9jLTa2BtkQCkfnX4qeaPZzAGCKK',
      owner: 'ETN6xMmnftpcxroSinABZuAJM6XAganqRvNcbTcHV9s',
      price: 186500000000,
      pubkey: '6vrGhM7BmCMGcWQX9wSW87MkLQWqDkMsQdEAjniwsBFA'
    },
    {
      nftMint: 'HLCTwXVmi114J4nWphD2vimwCbhat9cxDmJ4Rv6rSEqr',
      owner: '2a8eghHjgRSCvGGD4XcD54sdWyJd5aX6tMWrosBzRnFD',
      price: 398000000000,
      pubkey: 'ABKceAbuoq6hb3QDd1PLHYmQijSwQEqKPh1tzGCM3iVV'
    },
    {
      nftMint: 'HetJzowAkDyJJXcwSVExmfcoEzGzwwAYHz5thbpmjrr6',
      owner: 'EJhytiNULnEZFV6nUguMpuwAuTZyMtGDLcnPzK8SCDGW',
      price: 246000000000,
      pubkey: 'Ftc3iAxEc8BR9Lc4MZFHrTSi7Vb3QixBwRMHp7Q4CQpY'
    },
    {
      nftMint: 'HwDUYXX6PoXFxMqb8CShiSWWR5bSbhHaorwY7wFhQ6wj',
      owner: 'HxaXScmaM9rTDAra2oFB5xv8VUMQMFqUwXmNvg79uADK',
      price: 195000000000,
      pubkey: 'ADUQm3PNUfmhJy9BmXBVkW6w7AFHKKtg2Ws4XHXqDHx2'
    }
  ]
}
📀
MintList