make an script to find what specific solana token that top 100 wallet hold or what…
- User
make an script to find what specific solana token that top 100 wallet hold or what tokens is hold by many whale wallet. in python so i give a list of top solana wallets and you dig into it i give you csv file and your code must python
Assistant
Solana Token Holder Analysis Script
Here's a Python script that analyzes token holdings of top Solana wallets. The script will:
- Take a CSV file containing wallet addresses
- Query the Solana blockchain for token accounts associated with each wallet
- Analyze which tokens are held by multiple whales
- Output the results in a structured format
import pandas as pd import requests from solana.rpc.api import Client from solana.publickey import PublicKey from collections import defaultdict import time import json # Configuration SOLANA_RPC_URL = "https://api.mainnet-beta.solana.com" # You can use a different RPC endpoint if needed OUTPUT_FILE = "whale_token_analysis.csv" SLEEP_TIME = 0.1 # To avoid rate limiting def get_token_accounts(wallet_address): """Get all token accounts for a given wallet address""" try: solana_client = Client(SOLANA_RPC_URL) public_key = PublicKey(wallet_address) response = solana_client.get_token_accounts_by_owner(public_key, commitment="confirmed") return response['result']['value'] except Exception as e: print(f"Error fetching token accounts for {wallet_address}: {e}") return [] def get_token_info(mint_address): """Get token metadata from Solana API""" try: url = f"https://public-api.solscan.io/token/meta?tokenAddress={mint_address}" response = requests.get(url) if response.status_code == 200: return response.json() return None except Exception as e: print(f"Error fetching token info for {mint_address}: {e}") return None def analyze_whale_tokens(wallet_file): """Main analysis function""" # Read wallet addresses from CSV try: wallets_df = pd.read_csv(wallet_file) wallet_addresses = wallets_df['address'].tolist() # Assuming column is named 'address' except Exception as e: print(f"Error reading wallet file: {e}") return # Dictionary to store token holdings token_holders = defaultdict(int) token_details = {} wallet_holdings = {} print(f"Analyzing {len(wallet_addresses)} wallets...") for i, wallet in enumerate(wallet_addresses): print(f"Processing wallet {i+1}/{len(wallet_addresses)}: {wallet}") token_accounts = get_token_accounts(wallet) if not token_accounts: continue # Process each token account for account in token_accounts: mint_address = account['account']['data']['parsed']['info']['mint'] amount = account['account']['data']['parsed']['info']['tokenAmount']['amount'] decimals = account['account']['data']['parsed']['info']['tokenAmount']['decimals'] # Skip if amount is 0 if int(amount) == 0: continue # Update token holder count token_holders[mint_address] += 1 # Store wallet holdings if wallet not in wallet_holdings: wallet_holdings[wallet] = [] wallet_holdings[wallet].append({ 'mint': mint_address, 'amount': int(amount) / (10 ** int(decimals)) }) # Get token details if not already cached if mint_address not in token_details: token_info = get_token_info(mint_address) if token_info: token_details[mint_address] = token_info time.sleep(SLEEP_TIME) # Avoid rate limiting # Sort tokens by number of holders sorted_tokens = sorted(token_holders.items(), key=lambda x: x[1], reverse=True) # Prepare results results = [] for mint, count in sorted_tokens: token_info = token_details.get(mint, {}) results.append({ 'mint_address': mint, 'symbol': token_info.get('symbol', ''), 'name': token_info.get('name', ''), 'holders': count, 'total_supply': token_info.get('supply', ''), 'decimals': token_info.get('decimals', '') }) # Save to CSV results_df = pd.DataFrame(results) results_df.to_csv(OUTPUT_FILE, index=False) print(f"Analysis complete. Results saved to {OUTPUT_FILE}") # Save wallet holdings to JSON with open('wallet_holdings.json', 'w') as f: json.dump(wallet_holdings, f, indent=2) print("Wallet holdings saved to wallet_holdings.json") if __name__ == "__main__": import sys if len(sys.argv) < 2: print("Usage: python solana_whale_analysis.py <wallet_csv_file>") sys.exit(1) wallet_file = sys.argv[1] analyze_whale_tokens(wallet_file)How to Use This Script
-
Prerequisites:
- Install required packages:
pip install pandas requests solana - Prepare a CSV file with wallet addresses (one column named 'address')
- Install required packages:
-
Run the script:
python solana_whale_analysis.py your_wallet_list.csv -
Output:
whale_token_analysis.csv: Contains all tokens found, sorted by number of whale holderswallet_holdings.json: Detailed holdings for each wallet
Notes
- The script uses the Solana RPC API and Solscan's public API for token metadata.
- You might want to use a dedicated RPC endpoint (like QuickNode or Alchemy) for better performance.
- The script includes rate limiting to avoid being blocked by APIs.
- For very large wallet lists, you might need to adjust the sleep time or use a more robust solution.
Alternative Approach
If you need to analyze a very large number of wallets, consider:
- Using a database to store intermediate results
- Implementing parallel processing
- Using a more robust RPC provider with higher rate limits
Would you like me to modify any part of this script to better suit your needs?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.