A fairly common question on this forum is:
"I have a list of thousands of bitcoin addresses - how can I check their balances?"Presumably, this is asked by people who are still into hacking brainwallets and/or playing around with BrainFlayer (
https://github.com/ryancdotorg/brainflayer). Or why else do you need to check the current balances for thousands of bitcoin addresses; not a rhetorical question, please do tell me about other potential uses!
I'll show you a method for it that I sometimes use myself.
For the record, I should say that one politically correct answer is that you first need to install a bitcoin full node, let it download the complete blockchain, and on top on that add an Insight server (
https://insight.bitpay.com/) that you can query fast via API, and write and execute a script for it.
Now, I assume that most people are lazy and not willing to pull that off, or simply lack the technical skills required, so let me demonstrate my quick and dirty work-around that requires no installation or downloads. You just need a Linux machine.
The first thing we need to do is find other people's Insight servers that are fully exposed to the internet and respond to API-calls. A simple way of locating some of these is by searching Shodan (
https://www.shodan.io/) using this phrase: "port:3001 insight bitcoin"
Provided that you have a registered Shodan account (there are free - do sign up - you need to be registered to search for specific port numbers), you will find about 35 or so such servers. However, not all of them will work. Some hits are false positives, some do not respond to standard API-calls, some are simply down and maybe half or more are configured for other coins than BTC (be especially careful with BCH, as they will give you a wrong response, as they accept legacy bitcoin addresses).
When writing this, one hit that looked promising was IP: 18.141.53.197 Port: 3001 (this particular server may very well be down when you try this, also please don't hammer individual IP addresses!), so the first thing I did was to check this URL in my browser (note that it should be http and
not https, and the correct port 3001):
http://18.141.53.197:3001/Looks good! Now we need to query it with a known Bitcoin (BTC not BCH) that has funds in it. I semi-randomly picked this address, as it looks as it has been around a while and is well-funded:
https://www.blockchain.com/btc/address/39PVJ1sEVmFHJXjEG1D8kQa4Mk7f7jeMvASo, for confirmation that our discovered Insight server does its job as intended, let's look at this exact URL in our browser:
http://18.141.53.197:3001/api/addr/39PVJ1sEVmFHJXjEG1D8kQa4Mk7f7jeMvABingo! Lot's of JSON data. From a quick and manual glance, the balance corresponds to the one on blockchain.com too - definitely the droid we are looking for.
Repeat this step until you have 3-5 separate IP addresses that all work and display the desired data.
Finally, for automation, I have written a script (further below).
I want to strongly encourage you not to reuse the exact IP addresses as in this one, or they will not be up for much longer. DO change the IP addresses in the script to ones that you have discovered yourself.The script reads a text file with bitcoin addresses, so first create a such a file containing (for example):
1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL
17kbhNbkKkgNNJE23wvnLAbiddbqQ1eyJb
1QJpQuQ6PmFXoeKRnwjQrRZK9MMHpNBULC
and name that file "addresses.txt"
(Note that the list may contain both legacy addresses [starting with 1] and P2SH addresses [starting with 3], but not P2WPKH/Bech32 addresses [starting with bc1] - if you can find a working solution for Bech32 addresses, please let me know.)
In the same folder create a file called "checker" (for example with nano):
#!/bin/bash
while IFS= read -r line; do
line=${line//$'\n'/} #remove linebreak
line=${line//$'\r'/} #remove linebreak
balance=""
received=""
tx=""
# lP addresses for BTC Insight servers, need to be updated often
ip[0]="142.93.228.111"
ip[1]="147.135.252.43"
ip[2]="206.189.50.59"
ip[3]="88.99.139.98"
size=${#ip[@]}
index=$(($RANDOM % $size))
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
[ -z "$tx" ] && info=$(wget -qO- -T 0.5 http://$ip:3001/api/addr/$line)
balance=$(echo "$info" | grep -Po '"balanceSat":\K[0-9]+')
received=$(echo "$info" | grep -Po '"totalReceivedSat":\K[0-9]+')
tx=$(echo "$info" | grep -Po '"txApperances":\K[0-9]+')
echo "==================================="
echo "Address: $line"
echo "Balance: $balance"
echo "Received: $received"
echo "Transactions: $tx"
echo "$line,$balance,$received,$tx" >> balances.csv
done < "$1"
and issue the command "
chmod +x checker" to make it executable.
Unless you ask for it specifically, I won't comment or explain the code further.
All you need to know it that it outputs a file called "balances.csv" containing all the data. A very good reason to name the output .csv is that you can open it directly with Excel or any other spreadsheet program without any other pre-formation.
Ultimately, when you have everything ready: In the same directory a list of Bitcoin addresses called "addresses.txt" and an executable script called "checker", issue this command:
./checker addresses.txtand watch the magic happen in real-time. If everything is done right, it should output this in the terminal
===================================
Address: 1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL
Balance: 15818759376
Received: 4915056158983
Transactions: 4222
===================================
Address: 17kbhNbkKkgNNJE23wvnLAbiddbqQ1eyJb
Balance: 196303387
Received: 196303387
Transactions: 8
===================================
Address: 1QJpQuQ6PmFXoeKRnwjQrRZK9MMHpNBULC
Balance: 1913285
Received: 1913285
Transactions: 1
and the file "balances.csv" - try and open it in Excel - should contain:
1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL;15818759376;4915056158983;4222
17kbhNbkKkgNNJE23wvnLAbiddbqQ1eyJb;196303387;196303387;8
1QJpQuQ6PmFXoeKRnwjQrRZK9MMHpNBULC;1913285;1913285;1
With enough fresh IP addresses, it is in my experience easy to check many thousand bitcoin address balances in a few minutes.
Again - do not hammer individual IP addresses!
Comments? Questions?
We happy?