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.
- If
mergePendingUTXOs?: boolean
(Optional):- If
true
, includes pending UTXOs that are awaiting confirmation.
- If
filterSpentUTXOs?: boolean
(Optional):- If
true
, filters out any already spent UTXOs.
- If
-
Returns:
Promise<UTXOs>
: An array ofUTXO
objects representing the unspent outputs for the specified address.
Object Definitions
UTXO
ObjectProperty | Type | Description |
---|---|---|
transactionId | string | The ID of the transaction containing the UTXO. |
outputIndex | number | The index of the UTXO in the transaction outputs. |
value | bigint | The amount of Bitcoin (in satoshis) held by the UTXO. |
scriptPubKey | ScriptPubKey | The 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: