Skip to main content

Getting the Balance of an Address

The getBalance method allows you to retrieve the total balance of a Bitcoin address on the OP_NET network. This balance includes the sum of all unspent transaction outputs (UTXOs) associated with the address.


Method

getBalance(addressLike: string, filterOrdinals?: boolean): Promise<bigint>;
  • Parameters:

    • addressLike: string: The Bitcoin address whose balance you want to retrieve.
    • filterOrdinals?: boolean: (Optional) If true, excludes balances associated with Bitcoin Ordinals. Defaults to false.
  • Returns:

    • Promise<bigint>: The total balance of the specified address in satoshis.

Example Usage

Fetching Balance Without Filtering Ordinals

const address = "bcrt1qexampleaddress...";
const balance = await provider.getBalance(address);
console.log("Address Balance:", balance, "satoshis");

Fetching Balance with Ordinals Filter

const filteredBalance = await provider.getBalance(address, true);
console.log("Filtered Balance:", filteredBalance, "satoshis");

Best Practices

  • Use the filterOrdinals parameter to exclude any balances tied to Bitcoin Ordinals for a clearer view of spendable funds.
  • The returned balance is in satoshis, not BTC. Convert it to BTC by dividing by 1e8 if needed.

What’s Next?

Once you have the balance, you can: