Getting Top Token Holders in Solana Using Python
As a developer, you need to have access to the top wallet holders of a particular 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 Software Accounts?
Software accounts are native tokens belonging to SOL (Solana) programs. They represent funds used to implement and manage programs within the Solana network. To get the top software account holders, we need to identify which wallets hold a significant portion of these tokens.
get_program_accounts
function
In the solana.py
library, the get_program_accounts()
function is part of the spl
module, which provides access to SPL (Solana Program Interface) accounts. This function allows us to get the software accounts associated with specific token addresses.
from solana.py import account_info, system_program
def get_top_program_account_holders(token:str):
"""
Retrieves the top software account holders for a given token.
Arguments:
token (str): The address of the Solana program that owns the tokens.
Returns:
dict: A dictionary where keys are wallet addresses and values are the corresponding program accounts.
"""
Get the program accounts associated with the tokenaccounts = system_program.get_account_info(token).accounts
Filter out accounts outside the programprograms = [account for account in accounts if isinstance(account, account_info.AccountInfo)]
Initialize an empty dictionary to store the top holderstop_holders = {}
Check the program accounts and update the dictionaryfor program in programs:
wallet_address = account_info.get_program_account_info(program).address
if wallet_address is not in top_holders or sum(top_holders[wallet_address] / length(programs)) > 0.8:
Adjust threshold if necessarytop_holders[wallet_address] = program
return top_holders
Usage example
Let’s use this function to get the top software 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 check the Solana network latency before sending large requests. For more information or customizations to this limit, see the [Solana documentation](