How to spend UTXOs?

When you want to spend UTXOs of an address manually, you need to reference the specific transaction outputs (UTXOs) that you want to spend using Txid (transaction ID) and Vout (index number of the output in that transaction). Here’s how you can do it:

  1. Identify the UTXOs of an address you want to spend (API):

    • Every UTXO is referenced by a Txid, which is the unique identifier of the transaction that created the output.

    • The Vout (or index) specifies the particular output in that transaction. If a transaction has multiple outputs, each one is assigned a number starting from 0.

  2. Construct a new raw transaction (API):

    • Input: You specify the Txid and Vout of the UTXO you want to spend.

    • Output: You provide the address where you want to send the funds, along with the amount. Any change left over (if the UTXO is larger than the amount you want to send) is typically sent back to your own address as a new UTXO.

  3. Broadcast the transaction (API):

    • After constructing the transaction, it needs to be signed with your private key (API) to prove that you own the UTXO.

    • The signed transaction is then broadcast to the blockchain network, where it gets verified and added to a block.

Example: Let’s assume you want to spend a UTXO with the following details:

  • Txid: a2f0c9... (a 64-character hexadecimal string representing the transaction).

  • Vout: 1 (the second output of the transaction, as Vout is indexed from 0).

Let's assume If the selected UTXO’s amount is insufficient for the transaction you want to execute. In such scenarios, you would need to select multiple UTXOs to cover the required amount. To do this, you would create an array of transaction IDs (utxos) and an array of output indices (vouts_n) to combine multiple UTXOs, thereby gathering enough funds to complete the transaction.

You would use these details to create a new raw transaction where this UTXO is spent as input. You can also retrieve UTXO details using our API available under the Liaas Enterprise Plan (No Tokenization).

Last updated