Skip to main content

Getting UTXOs for an Address

The getUTXOs method allows you to fetch all Unspent Transaction Outputs (UTXOs) associated with a specific Bitcoin address.


Method

getUTXOs({
address,
optimize?,
mergePendingUTXOs?,
filterSpentUTXOs?,
}: RequestUTXOsParams): Promise<UTXOs>;
  • Parameters:

    • address: string: The Bitcoin address to fetch UTXOs for.
    • optimize?: boolean (Optional):
      • If true, optimizes UTXO selection for efficiency and minimal transaction fees.
    • mergePendingUTXOs?: boolean (Optional):
      • If true, includes pending UTXOs that are awaiting confirmation.
    • filterSpentUTXOs?: boolean (Optional):
      • If true, filters out any already spent UTXOs.
  • Returns:

    • Promise<UTXOs>: An array of UTXO objects representing the unspent outputs for the specified address.

Object Definitions

UTXO Object
PropertyTypeDescription
transactionIdstringThe ID of the transaction containing the UTXO.
outputIndexnumberThe index of the UTXO in the transaction outputs.
valuebigintThe amount of Bitcoin (in satoshis) held by the UTXO.
scriptPubKeyScriptPubKeyThe locking script for the UTXO.

Example Usage

Fetching UTXOs for an Address

const address = "bcrt1qexampleaddress...";
const utxos = await provider.utxoManager.getUTXOs({ address });

console.log("Fetched UTXOs:", utxos);

Optimized UTXO Fetching

const optimizedUtxos = await provider.utxoManager.getUTXOs({
address,
optimize: true,
});

console.log("Optimized UTXOs:", optimizedUtxos);

Best Practices

  • The optimize parameter is useful for minimizing transaction fees by selecting the smallest number of UTXOs.
  • Use the mergePendingUTXOs parameter if you need to include pending UTXOs that are not yet confirmed.
  • The filterSpentUTXOs parameter helps ensure that only unspent outputs are returned.

What’s Next?

After retrieving UTXOs, you can: