5

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 1

7

This assumes the solana CLI utils are available

  1. Create a new directory named ledger
  2. 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
  3. 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[*]}
1
  • what is genesis?
    – kafinsalim
    Aug 9, 2022 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.