Skip to content

Instantly share code, notes, and snippets.

@secp8x32
Last active April 7, 2022 12:45
Show Gist options
  • Save secp8x32/ea7cc295677f892dcbed50764f9d4d2c to your computer and use it in GitHub Desktop.
Save secp8x32/ea7cc295677f892dcbed50764f9d4d2c to your computer and use it in GitHub Desktop.
Python script for Bitcoin addresses bulk balance checking.
import argparse
import urllib3
from urllib3 import util
import json
import math
LIMIT = 120
SATOSHI = 1e+8
def check_balance(fi, fo):
print('loading addresses...')
f1 = open(fi)
f2 = open(fo, 'w')
addresses = []
for l in f1:
addresses.append(l.strip())
print('addresses loaded:', len(addresses))
print('getting balances info...')
f1.close()
http = urllib3.PoolManager(timeout=util.Timeout(10))
total = len(addresses)
steps = math.floor(total / LIMIT)
remind = total % LIMIT
for step in range(steps + 1):
url = 'https://blockchain.info/balance?active='
if step < steps:
for a in range(LIMIT):
url += addresses[a] + '|'
else:
for a in range(remind):
url += addresses[a] + '|'
url = url[:-1]
res = http.request('GET', url, timeout=util.Timeout(10), retries=util.Retry(10))
data = json.loads(res.data.decode('utf-8'))
for address in data:
balance = data[address]['final_balance'] / SATOSHI
n_tx = data[address]['n_tx']
b = '{0:.8f} '.format(balance)
f2.write(address + '\t\t\t' + b + '\t\t\t' + str(n_tx) + '\n')
print("%.2f" % ((step / (steps if steps > 0 else 1)) * 100), '%')
f2.close()
print('complete')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("fi", help="text file containing one address per line")
parser.add_argument("fo", help="text file to save addresses with balance details")
args = parser.parse_args()
fi = args.fi
fo = args.fo
check_balance(fi, fo)
@steveonthomas
Copy link

This is a great tool. How can I use it to check 6000 bitcoin addresses? It will only check 120 addresses and when I increase the limit to 6000 it throws an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment