0

I want to check multiple bitcoin addresses balance in python, can someone suggest a script that can do it fast and without getting api error.

3 Answers 3

2

You could do that by fetching an API from a Block Explorer

Or by adding a wallet on your Bitcoin node and fetching listunspent

without getting api error

Which API are you using?

1
  • Do you have any code that fetch balance from these API's I am using blockchain API Apr 3, 2022 at 5:58
1

you can request this API (it's free to use): https://rapidapi.com/juliakafarska/api/bitcoin-api

import requests

url = "https://bitcoin-api.p.rapidapi.com/balancesByAddress"

payload = {"addresses": ["16ftSEQ4ctQFDtVZiUBusQUjRrGhM3JYwe", "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo"]}
headers = {
    "content-type": "application/json",
    "X-RapidAPI-Key": "YOUR_KEY_HERE",
    "X-RapidAPI-Host": "bitcoin-api.p.rapidapi.com"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

response:

{
  "note": "Balances for 2 wallet addresses",
  "count": 2,
  "data": [
    {
      "id": 14122055,
      "address": "16ftSEQ4ctQFDtVZiUBusQUjRrGhM3JYwe",
      "btc": 0.00525093
    },
    {
      "id": 25721113,
      "address": "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",
      "btc": 0.00111145
    }
  ]
}
0

Alternative using https://github.com/Blockstream/esplora/blob/master/API.md

import requests

address_list = ["bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf", "1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY", "19SXCX6jvQxzfYfzRRMxjLBkqrNt6BUSJ2"]
for addr in address_list:
    print(requests.get(f"https://blockstream.info/api/address/{addr}").text)

output

{"address":"bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf","chain_stats":{"funded_txo_count":874627,"funded_txo_sum":1002983034753356,"spent_txo_count":874417,"spent_txo_sum":1002858836755824,"tx_count":844034},"mempool_stats":{"funded_txo_count":3,"funded_txo_sum":2604371991,"spent_txo_count":3,"spent_txo_sum":2650678155,"tx_count":3}}
{"address":"1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY","chain_stats":{"funded_txo_count":82575,"funded_txo_sum":535871315837629,"spent_txo_count":82540,"spent_txo_sum":535843538512098,"tx_count":82340},"mempool_stats":{"funded_txo_count":0,"funded_txo_sum":0,"spent_txo_count":0,"spent_txo_sum":0,"tx_count":0}}
{"address":"19SXCX6jvQxzfYfzRRMxjLBkqrNt6BUSJ2","chain_stats":{"funded_txo_count":1,"funded_txo_sum":43915252,"spent_txo_count":0,"spent_txo_sum":0,"tx_count":1},"mempool_stats":{"funded_txo_count":0,"funded_txo_sum":0,"spent_txo_count":0,"spent_txo_sum":0,"tx_count":0}}

Your Answer

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

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