I want to know how to get all account list using API.
The accounts are too many, so providing an API for that is inappropriate. Could you please explain in more detail what you're trying to achieve?
1 Like
I want to know the rich list.
You said it's inappropriate. It means, it is possible.
Can you tell me the way to get all account list?
Sure, it is possible, it's just inappropriate to develop an API for that. You can do it by running your own node and querying the DB of the node directly. Here's an example script, change the API_URL to your URL (localhost if you run one locally)
#!/usr/bin/env bash
set -euo pipefail
#-----------------------------------------------------------------------
# This script fetches the top-20 latest balances (balance_fxt.latest=true),
# then translates each ACCOUNT_ID into its human-readable accountRS and
# prints the balance as a float (divided by 100,000,000).
#
# Prerequisites:
# - ADMIN_PASSWORD must be set in the environment
# - curl, sed, awk (or nl) and bc or awk for arithmetic
#-----------------------------------------------------------------------
ADMIN_PASSWORD=${ADMIN_PASSWORD?:"Please export ADMIN_PASSWORD before running"}
API_URL="https://petko.ddns.net:27876"
TOTAL=998466231.25
echo "Fetching top 20 balances from $API_URL/dbshell..."
raw=$(curl -s -k \
-d "adminPassword=$ADMIN_PASSWORD" \
-d "line=select * from balance_fxt where latest=true order by balance desc limit 20" \
"$API_URL/dbshell")
echo
printf " %30s | %15s | %12s\n" "accountRS" "balance" "percentage"
printf " -------------------------------------------------------------\n"
#echo $raw
# skip header line, number the rows, then process each
echo "$raw" \
| awk 'NR>1 && /^[0-9]/' \
| nl -w2 -s' | ' \
| while IFS='|' read -r rank db_id account_id balance _rest; do
# trim spaces
rank=${rank// /}
account_id=${account_id// /}
balance=${balance// /}
# look up human-readable accountRS
acct_json=$(curl -s -k "$API_URL/nxt?requestType=getAccount&account=$account_id")
accountRS=$(echo "$acct_json" | sed -n 's/.*"accountRS":"\([^"]*\)".*/\1/p')
# convert raw FQT‐style balance to float
balance_float=$(awk "BEGIN { printf \"%.2f\", $balance/100000000 }")
# compute percentage of the total
pct=$(awk "BEGIN { printf \"%.4f\", ($balance_float / $TOTAL) * 100 }")
printf " %30s | %15s | %12s\n" \
"$accountRS" "$balance_float" "$pct"
done
echo
exit 0
1 Like