<p>When you have a bitcoin balance, that balance is actually unspent outputs from transactions your addresses have already received.</p>

<p>So when you want to send a raw transaction, what you include in that is the transactions and unspent outputs from those transactions... these can be from any address in your wallet. </p>

<p>The basic idea is;</p>

<p>createrawtransaction
signrawtransaction
sendrawtransaction</p>

<p>If you google around, you'll find plenty of examples of their use. </p>

CC BY-SA 3.0
2015-05-29T21:51:13.217Z
Coinbin seem to require internet/blockchain access in order to create a raw transaction. Is this true with all methods of creating raw transactions?
Alex Millar
CC BY-SA 3.0
2013-09-16T23:12:46.253Z
2013-09-16T23:12:46.253Z
ManreeRist
<pre><code>If this operation requires me to create a raw transaction, here's a working example assuming you have UTXOs:

UTXO 1: &quot;txid1&quot;, Index 0, Amount 0.01 BTC
UTXO 2: &quot;txid2&quot;, Index 1, Amount 0.02 BTC
Destination: &quot;your_destination_address&quot;

# Calculate transaction fee estimate (adjust the fee rate as needed)
TRANSACTION_FEE=$(bitcoin-cli estimatesmartfee 6 &quot;CONSERVATIVE&quot;)

# Calculate total input amount from UTXOs
TOTAL_INPUT=0.03

# Calculate the desired output amount
OUTPUT_AMOUNT=0.02

# Calculate the change amount
CHANGE_AMOUNT=$(echo &quot;$TOTAL_INPUT - $OUTPUT_AMOUNT - $TRANSACTION_FEE&quot; | bc)

# Create the raw transaction with change output
RAW_TRANSACTION_HEX=$(bitcoin-cli createrawtransaction '[
   {&quot;txid&quot;:&quot;txid1&quot;, &quot;vout&quot;:0},
   {&quot;txid&quot;:&quot;txid2&quot;, &quot;vout&quot;:1}
]' '{
   &quot;your_destination_address&quot;: '$OUTPUT_AMOUNT',
   &quot;your_change_address&quot;: '$CHANGE_AMOUNT'
}')

# Sign the raw transaction
SIGNED_TRANSACTION_HEX=$(bitcoin-cli signrawtransactionwithwallet &quot;$RAW_TRANSACTION_HEX&quot;)

# Broadcast the transaction
bitcoin-cli sendrawtransaction &quot;$SIGNED_TRANSACTION_HEX&quot;
</code></pre>
<p>Please correct me if I was wrong.</p>

CC BY-SA 4.0
2023-09-12T20:34:54.620Z
This might work, because `estimatesmartfee` returns a feerate in sat/kvB, and your transaction likely is less than 1 kvB. You are however deducting a feerate from an amount, and for a larger transaction that might be too little to achieve a confirmation. Why did you post a second answer instead of editing your first?
Murch
CC BY-SA 4.0
2023-08-29T05:33:26.567Z
2023-08-29T05:33:26.567Z
Mani T
<p>Assuming you have UTXOs:</p>
<ul>
<li>UTXO 1: &quot;txid1&quot;, Index 0, Amount 0.01 BTC</li>
<li>UTXO 2: &quot;txid2&quot;, Index 1, Amount 0.02 BTC</li>
<li>Destination: &quot;your_destination_address&quot;</li>
</ul>
<pre class="lang-bash prettyprint-override"><code># Create raw transaction
raw_tx=$(bitcoin-cli createrawtransaction '[{&quot;txid&quot;:&quot;txid1&quot;,&quot;vout&quot;:0}, {&quot;txid&quot;:&quot;txid2&quot;,&quot;vout&quot;:1}]' '{&quot;your_destination_address&quot;: 0.03}')

# Sign raw transaction
signed_tx=$(bitcoin-cli signrawtransactionwithwallet &quot;$raw_tx&quot;)

# Broadcast signed transaction
bitcoin-cli sendrawtransaction &quot;${signed_tx[&quot;hex&quot;]}&quot;
</code></pre>
<p>Replace <code>&quot;your_destination_address&quot;</code> with your actual destination address. Run these commands in your terminal with your Bitcoin Core node running.</p>
<p>Maybe test on Bitcoin testnet before using real funds.</p>

CC BY-SA 4.0
2023-08-28T13:55:01.533Z
Hi Mani, this is on the way to be a much better answer than the one from ten years ago, but could you please expand on two issues: 1) `createrawtransaction` does not automatically create a change output. Could you please include a warning to that effect and add some instructions on how to send change back to yourself. 2) The transaction in your example does not pay any fees, so it will not propagate on the network or get mined. Do you have an idea how to fix that? :)
Murch
CC BY-SA 4.0
2023-08-26T07:37:05.607Z
2023-08-26T07:37:05.607Z
Mani T
<p>I'm using bitcoind and would like to understand how to create transactions that send inputs from many specifically selected addresses (from my wallet) to one destination address. I want to do manually what the <em>sendtoaddress</em> command does automatically.</p>

<p>If this operation requires me to create a raw transaction could you please provide a working example? I already read <a href="https://en.bitcoin.it/wiki/Raw_Transactions" rel="nofollow">bitcoin.it:raw_transactions</a>, but it is hard to understand without an example and unfortunately the wiki article doesn't provide any.</p>

<p>I would appreciate help greatly.</p>

CC BY-SA 3.0
2013-09-16T14:44:45.423Z
Please be careful, I have seen many people accidently mess up with raw transactions. Such as sending hundreads of BTC as a miners fee or the likes.
MaxSan
CC BY-SA 3.0
2013-09-16T15:28:44.167Z
I will plan to test dipply with small amounts first.
Arsenius
CC BY-SA 3.0
2013-11-17T05:36:03.040Z
There is also the "testnet" which is made for testing
RentFree
CC BY-SA 4.0
2023-08-30T08:56:55.090Z
Please check rpc documentation before use it (https://developer.bitcoin.org/reference/rpc/).
Peter Lai
<bitcoind><raw-transaction>
How can I create a transaction that collects inputs from many addresses and sends them to one address in bitcoind?
Arsenius
# How can I create a transaction that collects inputs from many addresses and sends them to one address in bitcoind?

(Asked by: username_0 on 2013-09-16)

I'm using bitcoind and would like to understand how to create transactions that send inputs from many specifically selected addresses (from my wallet) to one destination address. I want to do manually what the *sendtoaddress* command does automatically.

If this operation requires me to create a raw transaction could you please provide a working example? I already read [bitcoin.it:raw\_transactions](https://en.bitcoin.it/wiki/Raw_Transactions), but it is hard to understand without an example and unfortunately the wiki article doesn't provide any.

I would appreciate help greatly.

**Tags:** bitcoind, raw-transaction

> **Comments:**
> **username_1**: Please be careful, I have seen many people accidently mess up with raw transactions. Such as sending hundreads of BTC as a miners fee or the likes.  
> **username_0**: I will plan to test dipply with small amounts first.  
> **username_2**: There is also the "testnet" which is made for testing  
> **username_3**: Please check rpc documentation before use it (https://developer.bitcoin.org/reference/rpc/).  

---

## 3 answers

### Answer by username_4 on 2013-09-16. Score: 3

When you have a bitcoin balance, that balance is actually unspent outputs from transactions your addresses have already received.

So when you want to send a raw transaction, what you include in that is the transactions and unspent outputs from those transactions... these can be from any address in your wallet.

The basic idea is;

createrawtransaction
signrawtransaction
sendrawtransaction

If you google around, you'll find plenty of examples of their use.

> **Comments:**
> **username_5**: Coinbin seem to require internet/blockchain access in order to create a raw transaction. Is this true with all methods of creating raw transactions?  

---

### Answer by username_6 on 2023-08-29. Score: 0

If this operation requires me to create a raw transaction, here's a working example assuming you have UTXOs:

UTXO 1: "txid1", Index 0, Amount 0.01 BTC
UTXO 2: "txid2", Index 1, Amount 0.02 BTC
Destination: "your_destination_address"

# Calculate transaction fee estimate (adjust the fee rate as needed)
TRANSACTION_FEE=$(bitcoin-cli estimatesmartfee 6 "CONSERVATIVE")

# Calculate total input amount from UTXOs
TOTAL_INPUT=0.03

# Calculate the desired output amount
OUTPUT_AMOUNT=0.02

# Calculate the change amount
CHANGE_AMOUNT=$(echo "$TOTAL_INPUT - $OUTPUT_AMOUNT - $TRANSACTION_FEE" | bc)

# Create the raw transaction with change output
RAW_TRANSACTION_HEX=$(bitcoin-cli createrawtransaction '[
   {"txid":"txid1", "vout":0},
   {"txid":"txid2", "vout":1}
]' '{
   "your_destination_address": '$OUTPUT_AMOUNT',
   "your_change_address": '$CHANGE_AMOUNT'
}')

# Sign the raw transaction
SIGNED_TRANSACTION_HEX=$(bitcoin-cli signrawtransactionwithwallet "$RAW_TRANSACTION_HEX")

# Broadcast the transaction
bitcoin-cli sendrawtransaction "$SIGNED_TRANSACTION_HEX"

Please correct me if I was wrong.

> **Comments:**
> **username_7**: This might work, because `estimatesmartfee` returns a feerate in sat/kvB, and your transaction likely is less than 1 kvB. You are however deducting a feerate from an amount, and for a larger transaction that might be too little to achieve a confirmation. Why did you post a second answer instead of editing your first?  

---

### Answer by username_6 on 2023-08-26. Score: -2

Assuming you have UTXOs:

UTXO 1: "txid1", Index 0, Amount 0.01 BTC
UTXO 2: "txid2", Index 1, Amount 0.02 BTC
Destination: "your_destination_address"

# Create raw transaction
raw_tx=$(bitcoin-cli createrawtransaction '[{"txid":"txid1","vout":0}, {"txid":"txid2","vout":1}]' '{"your_destination_address": 0.03}')

# Sign raw transaction
signed_tx=$(bitcoin-cli signrawtransactionwithwallet "$raw_tx")

# Broadcast signed transaction
bitcoin-cli sendrawtransaction "${signed_tx["hex"]}"

Replace "your_destination_address" with your actual destination address. Run these commands in your terminal with your Bitcoin Core node running.
Maybe test on Bitcoin testnet before using real funds.

> **Comments:**
> **username_7**: Hi Mani, this is on the way to be a much better answer than the one from ten years ago, but could you please expand on two issues: 1) `createrawtransaction` does not automatically create a change output. Could you please include a warning to that effect and add some instructions on how to send change back to yourself. 2) The transaction in your example does not pay any fees, so it will not propagate on the network or get mined. Do you have an idea how to fix that? :)  

---

