1

How can I get the total number of holder counts for any given Solana token in python?

Every API I use seems to give me an incorrect value and I need the exact value at the time of get request.

Hoping theres a free one out there that i can use?

2 Answers 2

2

To get the total number of holder counts for any given Solana token in Python, you can use the Helius API. Helius is a powerful tool that provides a wide range of features to interact with Solana data.

Here's a step-by-step guide on how to use the Helius API to get the total number of token holders:

  1. Sign up for a free account on the Helius website https://www.helius.xyz/.

  2. Once you have an account, log in and navigate to the "API Keys" section.

  3. Create a new API key and copy it.

  4. Install the required Python library:

pip install requests
  1. Use the following Python code to get the total number of token holders:
import requests

def get_token_holder_count(token_address, api_key):
    url = f"https://api.helius.xyz/v0/tokens/{token_address}/holders"
    headers = {
        "X-API-KEY": api_key
    }
    response = requests.get(url, headers=headers)
    data = response.json()
    total_holders = data["total"]
    return total_holders

token_address = "TOKEN_ADDRESS_HERE"
api_key = "YOUR_API_KEY_HERE"
total_holder_count = get_token_holder_count(token_address, api_key)
print(f"Total holder count for {token_address}: {total_holder_count}")

Replace TOKEN_ADDRESS_HERE with the address of the token you're interested in and YOUR_API_KEY_HERE with the API key you generated in step 3.

This code snippet uses the Helius API to fetch the total number of token holders. Make sure to replace the placeholders with your actual token address and API key.

For more detailed examples and documentation, you can visit the Helius API documentation at https://docs.helius.xyz/.

1

Getting this information requires a getProgramAccounts call and is slow and expensive so most free options use an indexed value which is why the APIs you're using feel out of date. There are several providers working on real-time holder counts and Birdeye and Solscan have paid plans that I believe are close.

If you want to do this yourself, you can call the .getProgramAccounts call on your RPC on the AssociatedTokenProgram and filter by mint and balance. Here's an example: https://solanacookbook.com/guides/get-program-accounts.html#filters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.