Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium-2505· Mistral AIHugging Face LMArena Human Preference 140K

make an script to find what specific solana token that top 100 wallet hold or what…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o4-mini-2025-04-16’s answer.
  1. 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

  2. Mistral Assistant

    Solana Token Holder Analysis Script

    Here's a Python script that analyzes token holdings of top Solana wallets. The script will:

    1. Take a CSV file containing wallet addresses
    2. Query the Solana blockchain for token accounts associated with each wallet
    3. Analyze which tokens are held by multiple whales
    4. 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

    1. Prerequisites:

      • Install required packages: pip install pandas requests solana
      • Prepare a CSV file with wallet addresses (one column named 'address')
    2. Run the script:

      python solana_whale_analysis.py your_wallet_list.csv
      
    3. Output:

      • whale_token_analysis.csv: Contains all tokens found, sorted by number of whale holders
      • wallet_holdings.json: Detailed holdings for each wallet

    Notes

    1. The script uses the Solana RPC API and Solscan's public API for token metadata.
    2. You might want to use a dedicated RPC endpoint (like QuickNode or Alchemy) for better performance.
    3. The script includes rate limiting to avoid being blocked by APIs.
    4. 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:

    1. Using a database to store intermediate results
    2. Implementing parallel processing
    3. 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?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.