Fetch User Account details based on its referrer, you can also fetch referrer accounts based on it's referrer address
On drift, users can be referred by other users. The referrer field indicates the user public key that referred the authority user. We can get User accounts referred by a particular referrer by querying the drift_UserStats account.
You can directly copy paste this code on replit and see it in action.
Fetch UserStats details by referrer
constSHYFT_API_KEY="YOUR-API-KEY";asyncfunctiongetDataByGraphQl(refAddress) {//get userStats by referrerconstoperationsDoc=` query MyQuery { drift_UserStats( where: {referrer: {_eq: ${JSON.stringify(refAddress)}}} ) { disableUpdatePerpBidAskTwap isReferrer referrer authority } } `; //graphQl queryconstresult=awaitfetch( `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", }), }, );returnawaitresult.json();}asyncfunctiongetUserStatsByReferrer(referrerPubkey) {const { errors,data } =awaitgetDataByGraphQl(reffererPubkey);if (errors) {console.error(errors);console.log("Some Error Occured, please check your API key or try again"); }console.dir(data, { depth:null });}getUserStatsByReferrer("GXNAdSaMwPqRr36DHK8YAi8CoKN83PvwUYDGb8YzKQag");//you can replace with the required referrer address