Skip to main content

Look Up the Address Balance for a Wallet for Bitcoin on QuickNode

Created on
Updated on
Nov 26, 2024

3 min read

Overview

If you're running your own Bitcoin node, you may want the ability to look up the balance of an address that you do not own. The first time this happens, you might create a watch-only wallet and add the address in question. This works, but then you'll need to add another one. If you've built a wallet and you're running a (non-spv) light client, then this strategy won't scale - your Bitcoin node will run out of memory.

That's why QuickNode has made a specific add-on, BTC Blockbook JSON-RPC Add-On, available for customers who wish to access the Bitcoin network. It includes 3 RPC methods that allow you to supply a Bitcoin address or an XPub key and retrieve its balance, transactions, and UTXOs.

An XPuB key, short for Extended Public Key, is a hierarchical deterministic key derived from a master public key in cryptocurrencies like Bitcoin. It is used to generate a series of public keys that can receive funds.

An Unspent Transaction Output (UTXO) in Bitcoin refers to the unspent coins resulting from previous transactions, which are stored in the blockchain and can be used as inputs for future transactions.

Blockbook RPC Add-On methods are explained below.


  • bb_getUTXOs - Returns array of unspent transaction outputs of address or xpub.
  • bb_getXPUB - Returns balances and transactions of an xpub or output descriptor.
  • bb_getAddress - Returns balances and transactions of an address. The returned transactions are sorted by block height, newest blocks first.

In this guide, we'll focus on the bb_getAddress RPC method to retrieve the balance of a Bitcoin address.

Let's take a quick look at how you can set up and use this RPC method.

Creating a Bitcoin Endpoint on QuickNode

To create your Bitcoin endpoint on QuickNode, select the Bitcoin chain and choose the Mainnet network. Click Continue.

Next, you will be asked to configure add-ons. Since the Blockbook RPC Add-On is a paid add-on, you will need a paid QuickNode plan. Select a plan based on your needs. (see Blockbook RPC Add-On for the details).

After creating your endpoint with the add-on, copy your QuickNode HTTP Provider URL.

Example Call

Now, we're ready to put our new add-on to the test! Open a terminal window and run the cURL command below. Make sure to change YOUR_QUICKNODE_HTTP_PROVIDER_URL to your Quicknode HTTP Provider URL.

In this example, we will look up the address balance and recent ten transactions of the following Bitcoin address: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa. You can change the address or other parameters based on your needs.

curl YOUR_QUICKNODE_HTTP_PROVIDER_URL \
--header 'Content-Type: application/json' \
--data '{"method": "bb_getaddress", "params": ["1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", {"page": 1, "size": 10, "fromHeight": 0, "details": "txids"}]}'
  • page: The page you would like to retrieve
  • size: The number of transactions you would like on each page
  • fromHeight: Filter of the returned transactions from block height
  • details: Option to specify the return data structure. It must be one of the following values: basic, txids, or txs

See QuickNode Bitcoin API Documentation for the details.

(Optional) To format the JSON output to look more structured and include syntax highlighting, you can use a library such as pjson or jq.

The output should look something like this with pjson or jq:

The unit of balance, total received amount and total sent amount results are Satoshi (Sat) which is the smallest unit of Bitcoin. Each Bitcoin equals to 100 million Satoshis. So, the address' balance is 72.63430323 BTC at the time this guide is written.

Conclusion

Great job! Now, it is possible to obtain balance, total received amount, total sent amount, total transaction amount, and latest transaction ids of any Bitcoin address easily. Check out the QuickNode Marketplace for more tools to effortlessly develop your Web3 applications.

Make sure to also subscribe to our newsletter for more articles and guides. Feel free to reach out to us via Twitter if you have any feedback. You can always chat with us on our Discord community server, featuring some of the coolest developers you'll ever meet :)

We also want to thank the entire bcoin team and Matthew Zipkin specifically for making awesome software and guiding our team in supporting bcoin for the QuickNode pro network!

We ❤️ Feedback!

Let us know if you have any feedback or requests for new topics. We'd love to hear from you.

Share this guide