$npx -y skills add AlexAI-MCP/hermes-CCC --skill solanaQuery Solana blockchain data — SOL balances, SPL tokens, transactions, programs, and NFTs via JSON RPC API.
| 1 | # Solana Blockchain |
| 2 | |
| 3 | Query Solana on-chain data via JSON RPC. No API key required for public endpoints. |
| 4 | |
| 5 | ## RPC Endpoints |
| 6 | |
| 7 | ``` |
| 8 | Mainnet: https://api.mainnet-beta.solana.com |
| 9 | Devnet: https://api.devnet.solana.com |
| 10 | Testnet: https://api.testnet.solana.com |
| 11 | ``` |
| 12 | |
| 13 | ## Python Setup |
| 14 | |
| 15 | ```python |
| 16 | import urllib.request, json |
| 17 | |
| 18 | RPC = "https://api.mainnet-beta.solana.com" |
| 19 | |
| 20 | def rpc(method, params=[]): |
| 21 | payload = json.dumps({ |
| 22 | "jsonrpc": "2.0", "id": 1, |
| 23 | "method": method, "params": params |
| 24 | }).encode() |
| 25 | req = urllib.request.Request( |
| 26 | RPC, data=payload, |
| 27 | headers={"Content-Type": "application/json"} |
| 28 | ) |
| 29 | with urllib.request.urlopen(req, timeout=10) as r: |
| 30 | resp = json.loads(r.read()) |
| 31 | if "error" in resp: |
| 32 | raise Exception(resp["error"]) |
| 33 | return resp["result"] |
| 34 | ``` |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## SOL Balance |
| 39 | |
| 40 | ```python |
| 41 | def get_sol_balance(pubkey): |
| 42 | result = rpc("getBalance", [pubkey]) |
| 43 | return result["value"] / 1e9 # lamports → SOL |
| 44 | |
| 45 | addr = "YourWalletPublicKey..." |
| 46 | print(f"Balance: {get_sol_balance(addr):.4f} SOL") |
| 47 | ``` |
| 48 | |
| 49 | --- |
| 50 | |
| 51 | ## SPL Token Accounts |
| 52 | |
| 53 | ```python |
| 54 | def get_token_accounts(pubkey): |
| 55 | result = rpc("getTokenAccountsByOwner", [ |
| 56 | pubkey, |
| 57 | {"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}, |
| 58 | {"encoding": "jsonParsed"} |
| 59 | ]) |
| 60 | return result["value"] |
| 61 | |
| 62 | accounts = get_token_accounts(addr) |
| 63 | for acc in accounts: |
| 64 | info = acc["account"]["data"]["parsed"]["info"] |
| 65 | mint = info["mint"] |
| 66 | amount = info["tokenAmount"]["uiAmount"] |
| 67 | print(f"Token: {mint[:8]}... Balance: {amount}") |
| 68 | ``` |
| 69 | |
| 70 | --- |
| 71 | |
| 72 | ## Transaction Details |
| 73 | |
| 74 | ```python |
| 75 | def get_tx(signature): |
| 76 | return rpc("getTransaction", [ |
| 77 | signature, |
| 78 | {"encoding": "jsonParsed", "maxSupportedTransactionVersion": 0} |
| 79 | ]) |
| 80 | |
| 81 | def get_recent_txs(pubkey, limit=10): |
| 82 | sigs = rpc("getSignaturesForAddress", [pubkey, {"limit": limit}]) |
| 83 | return [s["signature"] for s in sigs] |
| 84 | ``` |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## Account Info |
| 89 | |
| 90 | ```python |
| 91 | def get_account(pubkey): |
| 92 | return rpc("getAccountInfo", [pubkey, {"encoding": "jsonParsed"}]) |
| 93 | |
| 94 | info = get_account(addr) |
| 95 | print(f"Lamports: {info['value']['lamports']}") |
| 96 | print(f"Owner: {info['value']['owner']}") |
| 97 | print(f"Executable: {info['value']['executable']}") |
| 98 | ``` |
| 99 | |
| 100 | --- |
| 101 | |
| 102 | ## Network Stats |
| 103 | |
| 104 | ```python |
| 105 | def get_slot(): |
| 106 | return rpc("getSlot") |
| 107 | |
| 108 | def get_epoch_info(): |
| 109 | return rpc("getEpochInfo") |
| 110 | |
| 111 | def get_recent_performance(): |
| 112 | return rpc("getRecentPerformanceSamples", [5]) |
| 113 | |
| 114 | print(f"Current slot: {get_slot()}") |
| 115 | epoch = get_epoch_info() |
| 116 | print(f"Epoch: {epoch['epoch']}, Slot: {epoch['slotIndex']}/{epoch['slotsInEpoch']}") |
| 117 | ``` |
| 118 | |
| 119 | --- |
| 120 | |
| 121 | ## SOL Price |
| 122 | |
| 123 | ```python |
| 124 | def get_sol_price(): |
| 125 | url = "https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd" |
| 126 | with urllib.request.urlopen(url) as r: |
| 127 | return json.loads(r.read())["solana"]["usd"] |
| 128 | |
| 129 | price = get_sol_price() |
| 130 | bal = get_sol_balance(addr) |
| 131 | print(f"Portfolio: ${bal * price:.2f} USD") |
| 132 | ``` |
| 133 | |
| 134 | --- |
| 135 | |
| 136 | ## Solana CLI (alternative) |
| 137 | |
| 138 | ```bash |
| 139 | # Install |
| 140 | sh -c "$(curl -sSfL https://release.solana.com/stable/install)" |
| 141 | |
| 142 | # Balance |
| 143 | solana balance WALLET_ADDRESS |
| 144 | |
| 145 | # Transaction history |
| 146 | solana transaction-history WALLET_ADDRESS --limit 10 |
| 147 | |
| 148 | # Set network |
| 149 | solana config set --url mainnet-beta |
| 150 | ``` |
| 151 | |
| 152 | --- |
| 153 | |
| 154 | ## Helius / QuickNode (enhanced APIs) |
| 155 | |
| 156 | For NFT data, DAS API, and higher rate limits: |
| 157 | ```python |
| 158 | # Helius (free tier available) |
| 159 | RPC = "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY" |
| 160 | ``` |