Given access to Solana validator node and solana
command, how to export a list of all account addresses with positive balance (at the latest block)? Preferably in CSV format.
1 Answer
This assumes the solana CLI utils are available
- Create a new directory named
ledger
- Download genesis and a snapshot (full and incremental if applicable) from the target cluster and move them inside. Use something like [1] to list available source validators and use a single source for all files
- Use ledger tool to dump all accounts to JSON and consume however you please
solana-ledger-tool --ledger ./ledger accounts --output json
[1] (requires jq
)
!/usr/bin/env bash
cluster=devnet # one of `localhost`, `devnet`, `testnet`, `mainnet-beta` or custom RPC URL
canonical_snapshot_url() {
local -r relative_url="${1:?'missing required arg 1: `relative_url`'}"
url="$(wget -nv --connect-timeout 3 --tries 1 --method HEAD "$relative_url" 2>&1)"
local -r rc=$?
if [[ $rc -eq 0 ]]; then
cut -d' ' -f4 <<<"$url"
fi
return $rc
}
pids=()
while read RPCHOST; do
(
full_url="$(canonical_snapshot_url http://${RPCHOST}/snapshot.tar.bz2)"
if [[ 0 = $? ]]; then
gen_url="$(canonical_snapshot_url http://${RPCHOST}/genesis.tar.bz2)"
out="$gen_url\n$full_url"
inc_url="$(canonical_snapshot_url http://${RPCHOST}/incremental-snapshot.tar.bz2)"
if [[ 0 = $? ]]; then
out+="\n$inc_url"
fi
echo -e "$out\n --"
fi
) &
pids+=($!)
done < <(solana -u "$cluster" gossip --output json | jq -r '.[].rpcHost | select (. != null)')
wait ${pids[*]}