Get Active Listings of a Wallet
Get all active listings of a wallet on Tensor marketplace using GraphQL
Tensor has two programs which contains active listings.
Tensor Swap stores active listings in SingleListing account
Tensor cNFT stores listing data in ListState account.
Cross program query is possible here. You can query both programs in a single graphQL call.
With Shyft's SuperIndexer, you can query accounts data through GraphQL. We will be applying a where filter on owner field of the accounts data. This will give us all active listings for that owner (wallet).
Tensor Cross Program Query
We will query both Tensor programs, cNFT and Tensor Swap in a single call, and see the power of cross program queries, thanks to GraphQL APIs.
You can directly copy paste this code on replit and see it in action.
import { gql, GraphQLClient } from "graphql-request";
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,
},
});
async function getAllListingsOnTensor(walletAddr:string) {
//you can select the fields as per your requirement
const query = gql`
query MyQuery {
TENSOR_CNFT_listState(
where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
) {
_lamports
amount
assetId
currency
expiry
makerBroker
owner
privateTaker
rentPayer
version
}
Tensor_SingleListing(
where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
) {
bump
lamports
nftMint
owner
price
}
}
`;
const response = await graphQLClient.request(query);
console.dir(response,{depth: null});
}
//replace with the wallet address you want to query
getAllListingsOnTensor('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')
Active Listings for Tensor Swap (normal NFTs)
import { gql, GraphQLClient } from "graphql-request";
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,
},
});
async function getAllListingsByWallet(walletAddr:string) {
//you can select the fields as per your requirement
const query = gql`
query MyQuery {
Tensor_SingleListing(
where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
) {
price
owner
nftMint
pubkey
}
}
`;
const response = await graphQLClient.request(query);
console.dir(response,{depth: null});
}
//replace with the wallet address you want to query
getAllListingsByWallet('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')
Active Listings for Tensor cNFT
You can also query compressed NFT listings on Tensor, using the following code.
import { gql, GraphQLClient } from "graphql-request";
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,
},
});
async function getAllListingsByWallet(walletAddr:string) {
//you can select the fields as per your requirement
const query = gql`
query MyQuery {
TENSOR_CNFT_listState(
where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
) {
version
rentPayer
pubkey
owner
assetId
expiry
amount
}
}
`;
const response = await graphQLClient.request(query);
console.dir(response,{depth: null});
}
//replace with the wallet address you want to query
getAllListingsByWallet('5GAPWPNhsQWZ9V61cdSUY4Dy4qm1shN2tddB1gibz5zM')
Last updated
Was this helpful?