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();
{ //response shortened for visibility
"data": {
"tensor_bid_BidState": [
{
"bidAmount": 1500000000,
"bidder": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"expiry": 1740103769,
"nftMint": "tpLApHuN2pwyAJd2bByxTsitzXWL5LaH5YqwFZMx1Kt",
"pubkey": "6tJFEvJtgbBpoWCovwH291vWGA14Je1Baja5i4xyR5Fj"
},
{
"bidAmount": 200000000,
"bidder": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"expiry": 1714172253,
"nftMint": "7zdU6BZVZCSfGKPSs2LwXYMqKzodrmxFJeZG85qyHjf2",
"pubkey": "4wijcue36SGQ8bLyB2j3ZqdigN5mEvT8PV8tfJfLk3uE"
}
],
"TENSOR_CNFT_bidState": [
{
"target": {
"assetId": {}
},
"targetId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
"owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"pubkey": "GaEU91W1WJ5diBvBbP4XWBuGnfGTduQkpi9F7VsAzbGH",
"expiry": 1740553188,
"currency": null,
"bidId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
"amount": 2250000000
},
{
"target": {
"assetId": {}
},
"targetId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
"owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"pubkey": "QgmyTZLWLYmLLTncyZiVfkjRhcmymPHoXavTqr6H9ka",
"expiry": 1740519924,
"currency": null,
"bidId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
"amount": 10000000
}
]
}
}
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();
{
"data": {
"tensor_bid_BidState": [
{
"bidAmount": 1500000000,
"bidder": "12LtD1mjCoo3G79rmq9N98Zgmq4qatwcMAxt1VnJrD8o",
"expiry": 1739712261,
"nftMint": "6hu69KxxXNATFFv5RScJVNu1AMLmBXdFSVGqjsKrdD78",
"pubkey": "AuqeTsxV5p4RHnsBPyzgZkT3XR24srjiGzbvkifQxdnf"
},
{
"bidAmount": 137000000,
"bidder": "12LtD1mjCoo3G79rmq9N98Zgmq4qatwcMAxt1VnJrD8o",
"expiry": 1739775972,
"nftMint": "DVhpDyG8nT8J5Q5XAUkf8Sj5pJHt2a6DCS8tLP1ZfaQG",
"pubkey": "Etw93NNH4bHh2ChhygVP3w5HTocPLJWnc73BNTECFUGu"
}
]
}
}
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();
{ //response shortened
"data": {
"TENSOR_CNFT_bidState": [
{
"target": {
"assetId": {}
},
"targetId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
"owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"pubkey": "GaEU91W1WJ5diBvBbP4XWBuGnfGTduQkpi9F7VsAzbGH",
"expiry": 1740553188,
"currency": null,
"bidId": "ECiihNS3R9PrKMLTBAA6RPCb4b27McxvjuX2f9ndnJg2",
"amount": 2250000000
},
{
"target": {
"assetId": {}
},
"targetId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
"owner": "HGjJQTpMHisEekSoPsFvBadHeDauyY9CopAEZSBUSt8F",
"pubkey": "QgmyTZLWLYmLLTncyZiVfkjRhcmymPHoXavTqr6H9ka",
"expiry": 1740519924,
"currency": null,
"bidId": "Dzn7k3qUC9nj1nVvH1jsNYKbHrJazW78zwhFTxe5ywFF",
"amount": 10000000
}
]
}
}
Last updated
Was this helpful?