Get User accounts based on authority
Fetch User Account details based on its authority
Fetch User Details for an Authority
const SHYFT_API_KEY = "YOUR-API-KEY";
async function getDataByGraphQl(authorityAddress) {
//get user by authority
const operationsDoc = `
query MyQuery {
drift_User(
limit: 10
where: {authority: {_eq: ${JSON.stringify(authorityAddress)}}}
) {
delegate
subAccountId
pubkey
authority
}
}
`; //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 getUserDetailsByAuthority(authorityPubkey) {
const { errors, data } = await getDataByGraphQl(authorityPubkey);
if (errors) {
console.error(errors);
console.log("Some Error Occured, please check your API key or try again");
}
console.dir(data, { depth: null });
}
getUserDetailsByAuthority("Ctae6pxZZYKQ2tZRavw1tEVhVN5YNRJRhTBFGDbipmtw")
//authority address of the user to be fetchedLast updated