Get all Pools by Owner
Getting all pools created by one particular wallet on Tensor
Pool details for a wallet can be fetched by applying a where filter on the owner field in Tensor's Pool Account.
Account Joins can be seen in action here! We fetch pool data joined with the associated margin account.
Natively in RPC calls, if a wallet owns 100 pools you would need to fetch margin accounts for each one separately to get the balance. But here we are joining the pool data with the associated margin account, so you get everything in a single call.
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-API-KEY`; //Shyft's gQl endpoint
const graphQLClient = new GraphQLClient(endpoint, {
method: `POST`,
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
}); //Initialize gQL Client
async function getAllPoolsByUser(walletAddr) {
//you can select particular fields as per your requirement
const query = gql`
query MyQuery {
Tensor_Pool(
where: {owner: {_eq: ${JSON.stringify(walletAddr)}}}
) {
frozen
createdUnixSeconds
Margin {
owner
poolsAttached
lamports
}
nftAuthority
nftsHeld
orderType
owner
}
}
`;
const response = await graphQLClient.request(query);
console.dir(response,{depth: null});
}
getAllPoolsByUser('9XNuYM6ktSL4KcATv3seDBVhWAmVHEU42foY4t7skygg')
//replace this address to get all Pools of one particular owner
Last updated
Was this helpful?