Getting Top Token Holders in Solana Using Python
As a developer, you need to have access to the top wallet holders of a specific token on a blockchain network like Solana. In this article, we will look at how to use Python and the solana.py library to achieve this goal.
What are Program Accounts?
Program accounts are native tokens belonging to SOL (Solana) programs. They represent funds used to deploy and manage programs on the Solana network. To get the top program account holders, we need to identify which wallets hold a significant portion of these tokens.
The get_program_accounts function
In the solana.py library, the get_program_accounts() function is part of the spl module, which provides access to the Solana Program Interface (SPL) accounts. This function allows us to retrieve the program accounts associated with specific token addresses.
from solana.py import account_info, system_program
def get_top_program_account_holders(token: str):
"""
Gets the top program account holders for a given token.
Arguments:
token (str): Address of the Solana program that owns the tokens.
Returns:
dict: Dictionary where keys are wallet addresses and values are their corresponding program accounts.
"""

Get program accounts associated with a tokenaccounts = system_program.get_account_info(token).accounts
Filter out non-program accountsprograms = [account for account in accounts if isinstance(account, account_info.AccountInfo)]
Initialize an empty dictionary to hold the top holderstop_holders = {}
Iterate through program accounts and update dictionaryfor program in programs:
wallet_address = account_info.get_program_account_info(program).address
if wallet_address not in top_holders or sum(top_holders[wallet_address] / len(programms)) > 0.8:
Adjust threshold as neededtop_holders[wallet_address] = program
return top_holders
Usage example
Let’s use this function to get the top program account holders for the SPL token.
token = "YOUR_SOLANA_PROGRAM_ADDRESS"
top_holders = get_top_program_account_holders(token)
print(top_holders)
Replace "YOUR_SOLANA_PROGRAM_ADDRESS" with your own Solana program address. The resulting dictionary will contain wallet addresses as keys and their corresponding program accounts as values.
Note
: This function has a time limit of 30 minutes per call, so you should check the Solana network latency before sending large requests. If you need more information or adjustments to this threshold, please refer to the [Solana documentation](