Not returning the top token holders on BASE NETWORK

For some reason this code is not returning the top holders of the token it is starting somewhere way below that and then just listing random balances I want it to return the top 10 holders why is it not doing that ?

import requests
import json

# Step 1: Access token
access_token = "real access token here"

# Step 2: GraphQL API endpoint and headers
url_graphql = "https://streaming.bitquery.io/graphql"
headers_graphql = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

# The GraphQL query
query = """
query MyQuery {
    EVM(network: base) {
        BalanceUpdates(
        where: {Currency: {SmartContract: {is: "0x6921B130D297cc43754afba22e5EAc0FBf8Db75b"}}}
        orderBy: {descendingByField: "balance"}
        limit: {count: 10}
        ) {
        BalanceUpdate {
            Address
        }
        balance: sum(of: BalanceUpdate_AmountInUSD, selectWhere: {ne: "0"})
        Currency {
            Name
            Symbol
            SmartContract
        }
        }
    }
}
"""

# Prepare the request payload
payload = {
    "query": query
}

# Send the POST request
response = requests.post(url_graphql, json=payload, headers=headers_graphql)

# Parse and print the response
data = json.loads(response.text)
print(json.dumps(data, indent=2))

Summary

This text will be hidden

Hello @scotsoradis121 ,

Below is the token holder query to get Top Holder of Base Token

query MyQuery {
  EVM(dataset: archive, network: base) {
    TokenHolders(
      date: "2024-10-06"
      tokenSmartContract: "0x6921B130D297cc43754afba22e5EAc0FBf8Db75b"
      orderBy: {descending: Balance_Amount}
      limit: {count: 10}
    ) {
      Holder {
        Address
      }
      Balance{
        Amount
      }
    }
  }
}

Docs - Token Holders API | Blockchain Data API (V2) (bitquery.io)

1 Like

It worked thanks Omkar!!!

Hello Omkar I have an additional question regarding this…How recent does bitquery get the data from base network because in the date I put “2024-10-07” and I the order of the top holders is more or less correct but some of the balances are not accurate as shown on basescan so I am wondering how old exactly is the most recent data that bit querey can pull.

If you run that code request and go base scan to holder #29 of that token and then see how many tokens the querey says they have they do not match it is alittle bit less so I am wondering why exactly that is ?

Hello @scotsoradis121 ,

The token holder archive currently only works on “archive” dataset. It is like 2 delay than Realtime.So that might be reason for some discrepancy as those address might have some activity during recent 2 hours

Thanks

1 Like