# 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)
