1

I am willing to write Python script to check for some public addresses balances. I understand that I need to access API of known exchanges (Coinbase, Binance). I also know that there will be limit of requests sent in time.

As far as I can see there is possibility to check for wallet balances. But what about checking some public BTC addresses?

3 Answers 3

1

You can access an API and be limited by their ToS but you don't have to.

All transactions (TX) and BTC addresses (pubKey) are public on the blockchain with the distinction that all TX are recorded, but pubKeys show up only once mentioned in a TX.

Assuming you're talking about bitcoin and not something else you should run bitcoind on your machine and query it locally without limitations.

bitcoin-cli getbalance

1
  • getbalance is about wallet, not transactions in the blockchain...
    – pbies
    Nov 6, 2022 at 5:02
1

You can use services like blockchain.com, blockchair.com or tokenview.io to explore crypto addresses. It will show you balance, a list of transactions, date and time and some additional info. As for your script, you can use requests library to send requests to API and receive JSON data or scrape the web-sites directly using requests and beautifulsoup.

1

Solution script:

#!/usr/bin/env python3

import requests

addr=input('Enter address to check: ')

if addr=='':
    exit()

r=requests.get('https://blockchain.info/q/addressbalance/'+addr)

if not r.status_code==200:
    print('Error',r.status_code)
    exit()

b=int(r.text)

print(addr,'\t',r.text,'sat\t',b/100000,'mBTC\t',b/100000000,'BTC')

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.