<p>It can be done offline and with no synced data.</p>
<p>Start:</p>
<pre><code>.\bitcoind.exe -datadir=c:\bitcoin -prune=550 -noconnect
</code></pre>
<p>Create transaction:</p>
<pre><code>.\bitcoin-cli.exe -datadir=c:\bitcoin createrawtransaction '[{\&quot;txid\&quot;:\&quot;some taxid\&quot;,\&quot;vout\&quot;:0}]' '{\&quot;some target address\&quot;:a_number}'
</code></pre>
<p>To not spend all the sum, of course, add a returning address:</p>
<pre><code>,\&quot;a returning address\&quot;:a_number
</code></pre>
<p>vout is the output in the input taxid, for example 1 input, 2 outputs(first for someone else, second is for returning coins at owner) then:
<code>\&quot;vout\&quot;:1</code>
, etc.</p>
<p>Count the returning number of characters: ~190 for 1 input 1 output, ~230 1 input 2 outputs,etc.</p>
<p>Then calculate the fee, for example, 10 satoshis per byte will be ~2300 for 1 input and 2 outputs. Then: sum - to_address - returning_address = fee</p>
<p>Sign the transaction:</p>
<pre><code>.\bitcoin-cli.exe -datadir=c:\bitcoin signrawtransactionwithkey &quot;from create&quot; '[\&quot;the private key\&quot;]' [{\&quot;txid\&quot;:\&quot;some taxid\&quot;,\&quot;vout\&quot;:1,\&quot;scriptPubKey\&quot;:\&quot;explained below\&quot;,\&quot;redeemScript\&quot;:\&quot;\&quot;,\&quot;amount\&quot;:taxid_exact_input}]'
</code></pre>
<p>Get scriptPubKey for example from here: <a href="https://live.blockcypher.com/btc/tx/here_is_the_taxid/" rel="nofollow noreferrer">https://live.blockcypher.com/btc/tx/here_is_the_taxid/</a> then &quot;Advanced Details&quot;, then &quot;API Call&quot;, then at the source output (1 in this case), the &quot;script&quot; value (76a9148a598937f5ffb018fd71520b7c9459391744e28688ac at my case).</p>
<p>Push the signed transaction, for example, from here:
<a href="https://live.blockcypher.com/btc/pushtx/" rel="nofollow noreferrer">https://live.blockcypher.com/btc/pushtx/</a></p>

CC BY-SA 4.0
2021-01-13T17:59:17.890Z
2022-03-23T06:03:04.907Z
2022-03-23T06:03:04.907Z
Sam
<p>The easiest way to do this by importing the address you generated on the offline Bitcoin Core client into an online fully synced Bitcoin-Core. The command is: <code>bitcoin-cli importaddress &lt;address&gt;</code>. The benefit of importing this address into the synced Bitcoin-Core machine is that you can use it as a watch-only address which will allow you to see all the UTXOs related to it. You can then use the command <code>bitcoin-cli listunspent</code> to show you all the UTXOs and then you can use the ones related to the address in question.</p>

<p><strong>Note: Below <code>txid</code>s and amounts are made up</strong>.<br>
Now, using the UTXOs that were shown in the <code>listunspent</code> output you can create a transaction on the online client using the <code>createrawtransaction</code> command. I deliberately used two UTXOs to show how this can be done for multiple UTXOs and also to show how other commands will look like if one of the outpoints in the inputs belong to a legacy address and the other outpoint belongs to a P2SH-P2WPKH address.</p>

<pre><code>bitcoin-cli createrawtransaction '[{"txid":"27893ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0},{"txid":"776be22ff789a86283b247f99f7b2c6f7f53185cb765570bc65c6e6bb7ed8558","vout":1}]' '{"12WJykFa1hqJUJ65QbFB8dS5XNJaR22w2S":0.1}' 
</code></pre>

<p>This would give you the below hexstring that you can copy over to your offline machine. </p>

<pre><code>output: 020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a89270000000000ffffffff5885edb76b6e5cc60b5765b75c18537f6f2c7b9ff947b28362a889f72fe26b770100000000ffffffff0180969800000000001976a9141083323e89f0f734c448cd16d5a5513afb841b1788ac00000000
</code></pre>

<p>Copy over that output on the offline machine in order to sign the transaction. Now <code>signrawtransaction</code> command was deprecated in v0.17 and removed since v0.18. In place of that we now have <code>signrawtransactionwithwallet</code> and <code>signrawtransactionwithkey</code>. You will use the former when you want to sign the transaction from a key belonging to your wallet in Bitcoin Core and use the latter when you want to sign a transaction with a key not in your wallet by passing the private key along with the command.</p>

<p>Since your address was generated from a key in the wallet, we will use the first command. After copying over the output of the <code>createrawtransaction</code> command we had got on the online client, we also need to provide the <code>sciptPubKey</code> and <code>redeemScript</code>. This is done so that the offline client knows what the locking script is for the outpoints and which key it needs to use as it does not have access to the transactions (since it is offline).</p>

<p>Now, use the command:</p>

<pre><code>bitcoin-cli signrawtransactionwithwallet "020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a89270000000000ffffffff5885edb76b6e5cc60b5765b75c18537f6f2c7b9ff947b28362a889f72fe26b770100000000ffffffff0180969800000000001976a9141083323e89f0f734c448cd16d5a5513afb841b1788ac00000000" 
'[{"txid":"27893ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0,"scriptPubKey":"76a914623ff66fb88ff802fe1b8eaff666ba52307eecb088ac","amount":0.09},
{"txid":"776be22ff789a86283b247f99f7b2c6f7f53185cb765570bc65c6e6bb7ed8558","vout":1, "scriptPubKey":"a914de7dad83bb2d6e9638d347dcb3c53fe238773c9387","redeemScript":"0014df7bcc159ade813e6bd6290d97ed0bc8987dc084", "amount":0.011}]' 
"ALL"
</code></pre>

<p>This would give you a signed transaction as an output. Let's call it <code>hexoutput</code>. A couple of things to note. If you pay close attention you will see that the second outpoint used in the input contains <code>redeemScript</code>. This is because it belonged to a P2SH-P2WPKH transaction and hence you need to provide the <code>redeemScript</code> next to the <code>scriptPubKey</code> field. For more info you can refer the documentation <a href="https://bitcoincore.org/en/doc/0.17.0/rpc/wallet/signrawtransactionwithwallet/" rel="noreferrer">here</a>. </p>

<p>Now copy this <code>hexoutput</code> over to your online Bitcoin-core client and use the below command to relay it over the network.</p>

<pre><code>bitcoin-cli sendrawtransaction hexoutput
</code></pre>

<p>This will give you a <code>txid</code> of the transaction as an output that you can use to monitor your transaction.</p>

CC BY-SA 4.0
2022-03-03T00:44:57.307Z
Why initiate the raw transaction on the online machine? Why not just make and sign the transaction on the offline machine, and copy the signed transaction over just for the broadcast?
Costa Michailidis
CC BY-SA 4.0
2019-08-25T17:23:28.693Z
2019-08-25T18:44:47.873Z
2019-08-25T18:44:47.873Z
Ugam Kamat
<p>I am setting up a cold wallet. How can I generate a signed raw transaction from bitcoin core wallet that controls some bitcoins?</p>

<p>PS: I generated the wallet using <code>getnewaddress</code> in console from the bitcoin-qt GUI</p>

<bitcoin-core><coldstorage><signrawtransaction><sendrawtransaction><offline-transactions>
How to send bitcoin from an offline Bitcoin Core that doesn't have a synced balance?
bbnn
# How to send bitcoin from an offline Bitcoin Core that doesn't have a synced balance?

(Asked by: username_0 on 2019-08-25)

I am setting up a cold wallet. How can I generate a signed raw transaction from bitcoin core wallet that controls some bitcoins?

PS: I generated the wallet using `getnewaddress` in console from the bitcoin-qt GUI

**Tags:** bitcoin-core, coldstorage, signrawtransaction, sendrawtransaction, offline-transactions


---

## 2 answers

### Answer by username_2 on 2019-08-25. Score: 7 | Accepted answer

The easiest way to do this by importing the address you generated on the offline Bitcoin Core client into an online fully synced Bitcoin-Core. The command is: bitcoin-cli importaddress . The benefit of importing this address into the synced Bitcoin-Core machine is that you can use it as a watch-only address which will allow you to see all the UTXOs related to it. You can then use the command bitcoin-cli listunspent to show you all the UTXOs and then you can use the ones related to the address in question.
Note: Below txids and amounts are made up.
Now, using the UTXOs that were shown in the listunspent output you can create a transaction on the online client using the createrawtransaction command. I deliberately used two UTXOs to show how this can be done for multiple UTXOs and also to show how other commands will look like if one of the outpoints in the inputs belong to a legacy address and the other outpoint belongs to a P2SH-P2WPKH address.
bitcoin-cli createrawtransaction '[{"txid":"27893ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0},{"txid":"776be22ff789a86283b247f99f7b2c6f7f53185cb765570bc65c6e6bb7ed8558","vout":1}]' '{"12WJykFa1hqJUJ65QbFB8dS5XNJaR22w2S":0.1}' 

This would give you the below hexstring that you can copy over to your offline machine. 
output: 020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a89270000000000ffffffff5885edb76b6e5cc60b5765b75c18537f6f2c7b9ff947b28362a889f72fe26b770100000000ffffffff0180969800000000001976a9141083323e89f0f734c448cd16d5a5513afb841b1788ac00000000

Copy over that output on the offline machine in order to sign the transaction. Now signrawtransaction command was deprecated in v0.17 and removed since v0.18. In place of that we now have signrawtransactionwithwallet and signrawtransactionwithkey. You will use the former when you want to sign the transaction from a key belonging to your wallet in Bitcoin Core and use the latter when you want to sign a transaction with a key not in your wallet by passing the private key along with the command.
Since your address was generated from a key in the wallet, we will use the first command. After copying over the output of the createrawtransaction command we had got on the online client, we also need to provide the sciptPubKey and redeemScript. This is done so that the offline client knows what the locking script is for the outpoints and which key it needs to use as it does not have access to the transactions (since it is offline).
Now, use the command:
bitcoin-cli signrawtransactionwithwallet "020000000291195eb278578e6941498e51d67105f6d0f33b1d1b562c444cd9dd27d83a89270000000000ffffffff5885edb76b6e5cc60b5765b75c18537f6f2c7b9ff947b28362a889f72fe26b770100000000ffffffff0180969800000000001976a9141083323e89f0f734c448cd16d5a5513afb841b1788ac00000000" 
'[{"txid":"27893ad827ddd94c442c561b1d3bf3d0f60571d6518e4941698e5778b25e1991","vout":0,"scriptPubKey":"76a914623ff66fb88ff802fe1b8eaff666ba52307eecb088ac","amount":0.09},
{"txid":"776be22ff789a86283b247f99f7b2c6f7f53185cb765570bc65c6e6bb7ed8558","vout":1, "scriptPubKey":"a914de7dad83bb2d6e9638d347dcb3c53fe238773c9387","redeemScript":"0014df7bcc159ade813e6bd6290d97ed0bc8987dc084", "amount":0.011}]' 
"ALL"

This would give you a signed transaction as an output. Let's call it hexoutput. A couple of things to note. If you pay close attention you will see that the second outpoint used in the input contains redeemScript. This is because it belonged to a P2SH-P2WPKH transaction and hence you need to provide the redeemScript next to the scriptPubKey field. For more info you can refer the documentation here. 
Now copy this hexoutput over to your online Bitcoin-core client and use the below command to relay it over the network.
bitcoin-cli sendrawtransaction hexoutput

This will give you a txid of the transaction as an output that you can use to monitor your transaction.

> **Comments:**
> **username_3**: Why initiate the raw transaction on the online machine? Why not just make and sign the transaction on the offline machine, and copy the signed transaction over just for the broadcast?  

---

### Answer by username_1 on 2021-01-13. Score: 1

It can be done offline and with no synced data.
Start:
.\bitcoind.exe -datadir=c:\bitcoin -prune=550 -noconnect

Create transaction:
.\bitcoin-cli.exe -datadir=c:\bitcoin createrawtransaction '[{\"txid\":\"some taxid\",\"vout\":0}]' '{\"some target address\":a_number}'

To not spend all the sum, of course, add a returning address:
,\"a returning address\":a_number

vout is the output in the input taxid, for example 1 input, 2 outputs(first for someone else, second is for returning coins at owner) then:
\"vout\":1
, etc.
Count the returning number of characters: ~190 for 1 input 1 output, ~230 1 input 2 outputs,etc.
Then calculate the fee, for example, 10 satoshis per byte will be ~2300 for 1 input and 2 outputs. Then: sum - to_address - returning_address = fee
Sign the transaction:
.\bitcoin-cli.exe -datadir=c:\bitcoin signrawtransactionwithkey "from create" '[\"the private key\"]' [{\"txid\":\"some taxid\",\"vout\":1,\"scriptPubKey\":\"explained below\",\"redeemScript\":\"\",\"amount\":taxid_exact_input}]'

Get scriptPubKey for example from here: https://live.blockcypher.com/btc/tx/here_is_the_taxid/ then "Advanced Details", then "API Call", then at the source output (1 in this case), the "script" value (76a9148a598937f5ffb018fd71520b7c9459391744e28688ac at my case).
Push the signed transaction, for example, from here:
https://live.blockcypher.com/btc/pushtx/


---

