Transaction Tutorial
Creating transactions is a fundamental task for most Bitcoin applications. This section explains how to use Bitcoin Core's RPC interface to create transactions with various attributes using Markdown formatting.
Simple Spending
Bitcoin Core offers several RPCs that handle all spending details, including change outputs and fee calculations. These RPCs should be used whenever possible to prevent satoshi loss.
Basic Transaction Example:
> bitcoin-cli -regtest getnewaddress
> bitcoin-cli -regtest sendtoaddress [address] [amount]
Key points:
- Automatically selects UTXOs
- Creates change outputs when needed
- Handles transaction fees appropriately
๐ Learn more about Bitcoin transactions
Simple Raw Transaction
Raw transaction RPCs enable custom transaction creation with delayed broadcasting. Caution is advised as errors can lead to permanent fund loss.
Creating a Raw Transaction:
> bitcoin-cli -regtest createrawtransaction '[inputs]' '[outputs]'
> bitcoin-cli -regtest signrawtransaction [raw_tx]
Important notes:
- Always verify output amounts
- Change outputs aren't created automatically
- Double-check fee calculations
Complex Raw Transaction
This example demonstrates creating a transaction with:
- 2 inputs
- 2 outputs
- Separate signing of each input
Transaction Structure:
{
"inputs": [
{"txid": "[hash]", "vout": [index]},
{"txid": "[hash]", "vout": [index]}
],
"outputs": {
"[address1]": [amount],
"[address2]": [amount]
}
}
Offline Signing
Offline signing allows transaction creation without immediate broadcasting. This process is commonly used by wallet programs for enhanced security.
Workflow:
- Create unsigned transaction
- Sign offline
- Broadcast later
๐ Advanced transaction security tips
FAQ
What's the minimum fee for a Bitcoin transaction?
Transaction fees vary based on network congestion and transaction size. Bitcoin Core automatically calculates appropriate fees.
How many confirmations are needed?
For small amounts, 1-3 confirmations are typically sufficient. Larger transactions may require 6+ confirmations.
Can I cancel a Bitcoin transaction?
Once broadcast, transactions cannot be canceled. However, unconfirmed transactions can sometimes be replaced with higher-fee transactions.
What's a UTXO?
Unspent Transaction Output (UTXO) represents spendable bitcoin amounts. The UTXO set includes all available transaction outputs.
How do multisig transactions work?
Multisig transactions require multiple signatures (e.g., 2-of-3) to spend funds, enhancing security for shared accounts.
What's the difference between raw and regular transactions?
Raw transactions provide more control but require manual fee calculation and output management. Regular transactions automate these processes.