# Get User details based on Referrer

On drift, users can be referred by other users. The <mark style="color:yellow;">referrer</mark> field indicates the user public key that referred the authority user. We can get User accounts referred by a particular referrer by querying the <mark style="color:yellow;">drift\_UserStats</mark> account.

You can directly copy paste this code on <mark style="color:yellow;">replit</mark> and see it in action.

#### Fetch UserStats details by referrer

{% tabs %}
{% tab title="Code Snippet" %}
{% code overflow="wrap" %}

```javascript
const SHYFT_API_KEY = "YOUR-API-KEY";

async function getDataByGraphQl(refAddress) {
  //get userStats by referrer
  const operationsDoc = `
      query MyQuery {
        drift_UserStats(
          where: {referrer: {_eq: ${JSON.stringify(refAddress)}}}
        ) {
          disableUpdatePerpBidAskTwap
          isReferrer
          referrer
          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 getUserStatsByReferrer(referrerPubkey) {
  const { errors, data } = await getDataByGraphQl(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

```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```json
{
  drift_UserStats: [
    {
      disableUpdatePerpBidAskTwap: false,
      isReferrer: false,
      referrer: "GXNAdSaMwPqRr36DHK8YAi8CoKN83PvwUYDGb8YzKQag",
      authority: "Ctae6pxZZYKQ2tZRavw1tEVhVN5YNRJRhTBFGDbipmtw"
    },
    {
      disableUpdatePerpBidAskTwap: false,
      isReferrer: false,
      referrer: "GXNAdSaMwPqRr36DHK8YAi8CoKN83PvwUYDGb8YzKQag",
      authority: "5pGoPFPJc1oDqnqzDqPYNe87vmxmGmug3QfX8PYXQnuM"
    }
  ]
}
```

{% endtab %}
{% endtabs %}

You can also fetch the referrer for a particular authority account, using the following query

```graphql
query MyQuery {
  drift_UserStats(
    where: {authority: {_eq: "2jiKcT8ZXEzkhW2uhvKS8Br1r9uDU1o4YUB62bYwtKeJ"}}
  ) {
    authority
    referrer
  }
}
```

The response will contain the referrer name for the given authority account (pubkey)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shyft.to/solana-indexers/case-studies/drift/get-user-details-based-on-referrer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
