Get User account for Delegate
Fetch and query a delegates for user accounts on Drift v2 Program .
Fetch user account for a particular delegate
const SHYFT_API_KEY = "YOUR-API-KEY";
async function getDataByGraphQl(delegateAddress) {
//get user by delegated account
const operationsDoc = `
query MyQuery {
drift_User(
limit: 10
where: {delegate: {_eq: ${JSON.stringify(delegateAddress)}}}
) {
delegate
authority
pubkey
}
}
`; //graphQl query
const result = await fetch(
`https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`, //SHYFT's GQL endpoint
{
method: "POST",
body: JSON.stringify({
query: operationsDoc,
variables: {},
operationName: "MyQuery",
}),
},
);
return await result.json();
}
async function getReserveCurrencyDetails(delegatePubkey) {
const { errors, data } = await getDataByGraphQl(delegatePubkey);
if (errors) {
console.error(errors);
console.log("Some Error Occured, please check your API key or try again");
}
console.dir(data, { depth: null });
}
getReserveCurrencyDetails("EBWSHvJmWkg1r2oUPDcKxfBxA1QG2fdZdAqH2EVNTzxs")Last updated