Bitcoin Balance API
  • Bitcoin Balance API
  • Payments
  • Error Codes
  • Postman
  • Endpoints
    • Balance
    • UTXO
Powered by GitBook
On this page
  • Make a request (testnet)
  • Make a request (mainnet)
  • Response
  • Balance Calculation
  1. Endpoints

Balance

Get the balance of any Bitcoin address

PreviousPostmanNextUTXO

Last updated 3 months ago

Make a request (testnet)

The best way to interact with our API:

curl https://api-testnet.bitcoin-balance-api.com/v1/address/tb1qlw09ycnp3qgqw9alqgx93ed7cg5kmnyud326ky  
(async () => {
  try {
    const res = await fetch('https://api-testnet.bitcoin-balance-api.com/v1/address/tb1qlw09ycnp3qgqw9alqgx93ed7cg5kmnyud326ky');

    const response = await res.json();
    console.log(`Bitcoin Balance: ${response.balance}`);

  } catch (err) {
    console.log(err.message); //can be console.error
  }
})();
import requests
import json

address = "tb1qlw09ycnp3qgqw9alqgx93ed7cg5kmnyud326ky"

s = requests.Session()
r = s.get('https://api-testnet.bitcoin-balance-api.com/v1/address/%s' % (address))

if r.status_code == 200:
    response = json.loads(r.content)
    print(f'Bitcoin Balance: %s' % (response['balance']))
use LWP::UserAgent;
use JSON;

my $request = LWP::UserAgent->new()->get(
        "https://api-testnet.bitcoin-balance-api.com/v1/address/tb1qlw09ycnp3qgqw9alqgx93ed7cg5kmnyud326ky"
);
my $response = decode_json($request->content);
print "Bitcoin Balance: $response->{'balance'}";
require "net/https"
require "json"

url = URI.parse("https://api-testnet.bitcoin-balance-api.com/v1/address/tb1qlw09ycnp3qgqw9alqgx93ed7cg5kmnyud326ky")
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true
request = res.get(url.request_uri)
response = JSON.parse(request.body)
puts("Bitcoin Balance: #{response['balance']}")

Make a request (mainnet)

For mainnet a valid apikey is needed and needs to be send as a query parameter. You can for testing the api. The correct url for mainnet is:

https://api.bitcoin-balance-api.com/v1/address/34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo?apikey=$SECRET

Where $SECRET needs to be replaced with your own apikey.

Response

The response from the api contains two fields, status and balance. When status is 200 the request was successful and it will contain the value in the balance field. E.g.:

{ "status": 200, "balance": 19989726659 }

The status field can contain different responses like depending on the request.

Balance Calculation

The balance is in satoshi's and if you want to change it to BTC, it needs to be divided by 100000000. E.g.:

# Python Example
balance=7821967447
balance_btc=balance/100000000
print(f'Balance in Bitcoin: %s' % (balance_btc))
create a temporary mainnet api key
400, 401, 404, 422 or 500
Page cover image