Get active listings across marketplaces for a wallet
Get NFT listings from Tensor, Sniper and ME for a wallet in a single graphQl call.
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
})
}
);
//network is an optional param, which can be devnet also, defaults to mainnet-beta
return await result.json();
}
const listingsforWallet = '8pvTRunAQghgWE3sinNxqCUULaxhvXhyEknf5AQe29rB';
//wallet address for which we are fetching the listings
const operationsDoc = `
query MyQuery {
MAGIC_EDEN_V2_SellerTradeStateV2(
where: {seller: {_eq: ${JSON.stringify(listingsforWallet)}}}
) {
tokenMint
pubkey
seller
buyerPrice
expiry
}
Tensor_SingleListing(
where: {owner: {_eq: ${JSON.stringify(listingsforWallet)}}}
) {
owner
nftMint
price
}
SNIPER_MARKET_SOLNFTOrderV1(
where: {owner: {_eq: ${JSON.stringify(listingsforWallet)}}}
) {
nftMint
price
owner
}
}
`; //querying multiple marketplaces with one query
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