<p><code>signrawtransactionwithwallet</code> uses the wallet for two purposes:</p>

<ul>
<li>Finding the private keys necessary to sign with (which you dealt with by importing)</li>
<li>Finding the transaction outputs that are being spent (without this information you can't construct a valid transaction, and the offline wallet, being offline, does not have access to the transactions that credited you).</li>
</ul>

<p>There are a number of solutions for this, in order of increasing practicality:</p>

<ul>
<li>Copy the wallet.dat from the online system to the offline system, so it sees the transaction history (do not transfer it back, as it will contain private keys)</li>
<li>Use the <code>signrawtransactionwithkey</code> RPC, which lets you specify the private key and the UTXO information in the RPC call, so no importing is needed anymore on the offline system.</li>
<li>Use the PSBT style RPC calls; use <code>walletcreatefundedpsbt</code> on the offline system, sign it on the online system using <code>walletprocesspsbt</code>, extract a finished transaction using <code>finalizepsbt</code>, which you can broadcast using <code>sendrawtransaction</code>. The PSBT files contain all metadata needed for signing, including the old transaction (outputs) being spent.</li>
</ul>

CC BY-SA 4.0
2018-10-26T16:35:32.810Z
Thank you for your quick and precise answer. About **solution 2** : I tried this before, and _signrawtransactionwithkey_ gives me error code: -3 = "Missing redeemScript". About **solution 3**, which I didn't know at all, _walletcreatefundedpsbt_ gives me "Insufficient funds" error.
bitcoinmonkey
CC BY-SA 4.0
2018-10-26T16:49:26.780Z
About (2): If you're spending from a P2SH address you also need to provide `signrawtransactionwithkey` with the redeemScript (can be found using `getaddressinfo`). PSBT also stores this information directly.
Pieter Wuille
CC BY-SA 4.0
2018-10-26T16:51:16.773Z
About (3), sorry my advice was bad as you're doing the coin selection yourself. You can use `createrawtransaction` like you're doing now, then call `converttopsbt` on the result, then call `walletprocesspsbt` on the online system (which will add redeemscript and UTXO information), and then `walletprocesspsbt` on the offline system to sign, followed by `finalizepsbt` and `sendrawtransaction`. If this works I'll update my answer.
Pieter Wuille
CC BY-SA 4.0
2018-10-27T08:30:28.257Z
Thanks again Pieter, I just edited my question to allow a more precise output, as I could not get that to work.
bitcoinmonkey
CC BY-SA 4.0
2018-10-27T17:35:15.397Z
About (2), what you need is the "scriptPubKey" inside the "embedded" field; it gives the script that's wrapped in P2SH. Without it, the signer doesn't know what you're actually trying to sign (as it's only given a hash of the script).
Pieter Wuille
CC BY-SA 4.0
2018-10-27T17:35:54.923Z
About (3) that indeed looks like a bug; it will presumably be fixed in the 0.17.1 release.
Pieter Wuille
CC BY-SA 4.0
2018-10-27T17:37:07.833Z
Also, if you don't want to do coin selection yourself, you can use the `fundrawtransaction` or `walletcreatefundedpsbt` RPCs. You feed them the output you want to send, and these RPcs will add inputs and change from your wallet as necessary.
Pieter Wuille
CC BY-SA 4.0
2018-10-27T19:02:41.493Z
Thank you again. I updated the original post with what you suggested. Unfortunately, I could not achieve the "automatic coin selection" even after I read your answer to (https://bitcoin.stackexchange.com/questions/58920/what-is-a-workaround-to-fundrawtransaction-for-watchonly-addresses). The solution you provided with (2) did not work for me (missing amount), which is strange because amount is apparently specified in the raw transaction.
bitcoinmonkey
CC BY-SA 4.0
2018-10-27T19:37:34.867Z
(https://github.com/bitcoin/bitcoin/issues/14401) seems to be related to the abort of the bitcoind by the way
bitcoinmonkey
CC BY-SA 4.0
2018-10-29T13:31:54.587Z
`signrawtransactionwithkey` needs to know the amounts of the *inputs* you're signing; this information is not part of the raw transaction. You find the amounts in the listunspent output, and need to pass it in along with the UTXOs being spent.
Pieter Wuille
CC BY-SA 4.0
2018-11-06T19:23:40.690Z
Sorry but I could not make it work, with any of the solutions proposed. I'll just wait for a next bitcoin-core release to see if it works better.
bitcoinmonkey
CC BY-SA 4.0
2019-08-22T08:18:11.230Z
Peter's solution (3) works with v0.18.1 given the steps he detailed in the third comment.
thalisk
CC BY-SA 4.0
2018-10-26T16:20:22.820Z
2018-10-26T16:20:22.820Z
Pieter Wuille
<p>I have a very old Greg Maxwell tutorial for this slightly old question<br />
<a href="https://web.archive.org/web/20171124193914/https://people.xiph.org/%7Egreg/signdemo.txt" rel="nofollow noreferrer">https://web.archive.org/web/20171124193914/https://people.xiph.org/~greg/signdemo.txt</a><br />
The tutorial uses 'bitcoind' as the command because it was written before 'bitcoin-cli' became the correct command. Apart from this detail, the tutorial should still work with a recent Bitcoin Core version</p>
<p>I'm not sure why this discussion diverged to &quot;PSBT does this better&quot; without answering the question that was written, but I won't argue against &quot;PSBT does this better&quot;</p>
<p>The question is now hard to follow, has been altered in a train of thought manner, so it's possible I missed something</p>
<p>The question uses 'signrawtransactionwithwallet'<br />
The tutorial uses 'signrawtransaction'</p>
<p>The questioner tries to use 'getaddressinfo' to find the RedeemScript<br />
The tutorial uses 'decoderawtransaction' to expose the RedeemScript</p>
<p>Unless I'm reading the flow of advice incorrectly, the problem is that a cold wallet can not know the RedeemScript, and this is why 'signrawtransactionwithwallet' fails to work. 'signrawtransaction' accepts the RedeemScript as a parameter, and 'decoderawtransaction' exposes the RedeemScript</p>
<p>I haven't tried the method in the Greg Maxwell tutorial, but I hope this small contribution is useful to understanding the problem better</p>
<p>If I cannot find a newer offline signing tutorial, I will try to put aside some time to write a fresh version</p>

CC BY-SA 4.0
2020-09-02T14:40:46.440Z
2020-09-02T14:40:46.440Z
Louis Thompson
<p>I do not have enough reputation to reply on Pieter Wuille's answer, but I have tested using PSBT (solution 3) with bitcoin-core v0.18.0, it now works well for this. In my case, using PSBT was a lot easier than using <code>signrawtransactionwithkey</code>. The steps I've used are:</p>

<ol>
<li><code>createrawtransaction</code> on watch-only wallet.</li>
<li><code>fundrawtransaction</code> on watch-only wallet.</li>
<li><code>converttopsbt</code> on watch-only wallet.</li>
<li><code>walletprocesspsbt</code> on watch-only wallet. Not sure why this is necessary but it does change the PSBT string. I thought <code>converttopsbt</code> would do whatever this step does.</li>
<li><code>walletprocesspsbt</code> on offline wallet.</li>
<li><code>finalizepsbt</code> on offline wallet.</li>
</ol>

<p>It shouldn't make a difference, but for the record I've used the RPC API, not the command-line.</p>

CC BY-SA 4.0
2019-08-22T08:15:37.610Z
I think step 5 should be done on offline wallet.
thalisk
CC BY-SA 4.0
2019-08-22T12:10:34.080Z
The reason why step 4 is needed, is because the inputs are referenced by `txid:vout` and the offline wallet cannot know how to get the details needed (e.g. `scriptPubKey`) since it doesn't have any blocks. So `walletprocesspsbt` on the watch-only (onlline) wallet fills in this information (in particular the psbt's `inputs[]` part).
thalisk
CC BY-SA 4.0
2019-08-23T06:30:08.783Z
@ThalisK. You're right, sorry for the typo ! And about step 4, I understand that and agree, but I don't see why step 3 isn't already doing this. But anyway, it's not a problem to do it in two steps.
Clément
CC BY-SA 4.0
2019-08-23T10:02:59.297Z
As far as I understand `converttopsbt` literally does the conversion from one structure format (tx) to the other (psbt). It doesn't do lookup and filling in of data. `walletprocesspsbt` does the lookup and filling in. Separation of concerns keeps each command simple and focused.
thalisk
CC BY-SA 4.0
2019-07-05T15:58:01.360Z
2019-08-23T06:25:39.887Z
2019-08-23T06:25:39.887Z
Clément
<p>I know this subject has been discussed quite a lot, but after several <em>days</em> looking for this to work, I give up.</p>

<p>I want to create a transaction on a view-only wallet which is connected to the internet and synced, then sign this transaction on a "cold" offline machine that has the private key, then send this transaction on the view-only wallet.</p>

<blockquote>
  <p>View-only wallet will be [VOW]</p>
  
  <p>Offline cold wallet will be [OCW]</p>
  
  <p>Some other bitcoin wallet will be [SOW] (on another 3rd machine, that will play the peer)</p>
</blockquote>

<p>First let's simulate the nodes, with one node on each machine:</p>

<pre><code>[VOW] bitcoind -regtest -wallet=/path/daemon1.dat -datadir=/path/.bitcoin1 -rpcport=18334 -port=18434 -addnode=127.0.0.1:18435
[SOW] bitcoind -regtest -wallet=/path/daemon2.dat -datadir=/path/.bitcoin2 -rpcport=18335 -port=18435 -addnode=127.0.0.1:18434
[OCW] bitcoind -regtest  -datadir=/path2/.bitcoin -wallet=/path2/wallet -rpcport=18336 -port=18436
</code></pre>

<p>With these aliases to call the bitcoin-cli:</p>

<pre><code>alias BITVOW='bitcoin-cli -regtest -datadir=/path/.bitcoin1 -rpcport=18334'
alias BITSOW='bitcoin-cli -regtest -datadir=/path/.bitcoin2 -rpcport=18335'
alias BITOCW='bitcoin-cli -regtest -rpcport=18336'
</code></pre>

<p>So the two [VOW] and [SCW] connect to each other, no problem with that (they form a small 2 nodes network).</p>

<p>On the offline machine, I do this:</p>

<pre><code>$ BITOCW getnewaddress
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITOCW dumpprivkey
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj
</code></pre>

<p>I want to send 500 BTC to <strong>2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL</strong>, so I generate funds to the "other" wallet, to pay my wallet, with a generate to validate the transaction:</p>

<pre><code>$ BITSOW generate X
$ BITSOW getbalance
550.00000000
$ BITSOW sendtoaddress 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL 500
33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1
$ BITSOW generate 1
$ BITSOW getnewaddress
2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM
</code></pre>

<p>I will use this address <strong>2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM</strong> to receive funds from my main wallet with an offline signature.</p>

<p>I import the bitcoin address on a wallet-view wallet, and check the balance:</p>

<pre><code>$ BITVOW importaddress  2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITVOW getbalance "*" 0 true
500.00000000
</code></pre>

<p>Perfect. Now comes the part where I want to send thoses 500 back to <strong>2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM</strong> using an offline transaction signing.</p>

<p>First let's identify the TX that can be used:</p>

<pre><code>$ BITVOW listunspent 1 99999999 '["2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"]'
[
  {
    "txid": 
    "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
    "vout": 0,
    "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
    "label": "",
    "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
    "amount": 500.00000000,
    "confirmations": 1,
    "spendable": false,
    "solvable": false,
    "safe": true
  }
]
$ BITVOW createrawtransaction '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499.9999}'
</code></pre>

<p>This gets as a raw transaction (that I put in $RAW_TRANSACTION for example):</p>

<blockquote>
  <p>0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000</p>
</blockquote>

<p>Then, on the offline machine, I want to sign this using the private key:</p>

<pre><code>$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION
{
    "hex": "0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000",
    "complete": false,
    "errors": [
   {
   "txid": "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
  "vout": 0,
  "witness": [
  ],
  "scriptSig": "",
  "sequence": 4294967295,
  "error": "Input not found or already spent"
}
]
}
</code></pre>

<p>Thank you very much for your help!</p>

<p><strong>[EDIT]</strong>:I also tried this:</p>

<pre><code>$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]'
error code: -3
error message:
Missing amount for CTxOut(nValue=21000000.00000000, scriptPubKey=a9144b17c1384ded51b51a60915fa5)
</code></pre>

<p><strong>[EDIT]</strong></p>

<p>Here is what I tried using the provided solutions (2) and (3) from <em>Pieter Wuille</em>:</p>

<p><strong>(2)</strong>
I tried this on the offline system [OCW], in order to get RedeemScript for the signing process:</p>

<pre><code>BITOCW getaddressinfo 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL{
  "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
  "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
  "ismine": true,
  "iswatchonly": false,
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_keyhash",
  "hex": "0014dd296fa290135a7c18c3002c41cf020324538d5f",
  "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
  "embedded": {
    "isscript": false,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "dd296fa290135a7c18c3002c41cf020324538d5f",
    "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
    "address": "bcrt1qm55klg5szdd8cxxrqqkyrnczqvj98r2l8m5l0f",
    "scriptPubKey": "0014dd296fa290135a7c18c3002c41cf020324538d5f"
  },
  "label": "",
  "timestamp": 1540018166,
  "hdkeypath": "m/0'/0'/4'",
  "hdseedid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
  "hdmasterkeyid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
  "labels": [
    {
      "name": "",
      "purpose": "receive"
    }
  ]
}
</code></pre>

<p>Maybe I am missing something, but I could not find a proper RedeemScript for signing.</p>

<p><strong>(3)</strong>
First of all, I didn't know it was possible to do such a thing without doing the coin selection myself. If it is, I'd rather have the "online watch-only" wallet make the coin selection automatically so that I don't have to programmatically select the suitable inputs.</p>

<p>Then, following your advice, this is what i've tried so far, after the same <strong>createrawtransaction</strong> as above, on the online system:</p>

<pre><code>BITVOW converttopsbt 0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000
cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==
</code></pre>

<p>And:</p>

<pre><code>BITVOW walletprocesspsbt cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==
{
  "psbt": "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbtEbzL8i2dzUFq8RcAAAAASEcwRAIgVoSlc5RumxBU/O4gDzrFdXcxuCBDt30DczglDmuvSegCIFkZIqu1OS5UNncEThnNS8th+38lFf71PDa9Og2n3TKFAf7////Zq7QRMc7AhtcyGYE/HdvSA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F6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAAA",
  "complete": false
}
</code></pre>

<p>Then I exported this on the offline system and did:</p>

<pre><code>BITOCW  walletprocesspsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbtEbzL8i2dzUFq8RcAAAAASEcwRAIgVoSlc5RumxBU/O4gDzrFdXcxuCBDt30DczglDmuvSegCIFkZIqu1OS5UNncEThnNS8th+38lFf71PDa9Og2n3TKFAf7////Zq7QRMc7AhtcyGYE/HdvSAR146Dv659BXuzrHycdrcQAAAABIRzBEAiBctxeVGCoN8zlKnG19Tgs4GKnQ1r/Ge6Hjr/kIX0LJSQIgNHhYFpt2aabQEWA06apQpTcscoBH1hkDO9b9P3kNBKsB/v///0dInKhhB5SbX3zsU4+I8irL8UFXYDWqM2njZ8cDJQw4AAAAAEhHMEQCIEy0Fm9FwnEMSm6Cx37tMs8VFKNWypz3iXDZGinXpoG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TAwV35Z4FgNBlYt0d28gIgCQbediJ7kTw6Hr94o4I2IiwaD3xHFN8qQI0aNl5Bjh4B/v///zPoBvkyeie1HxFTJRUrG/J7pE67/XCDa8t+uxpZKwQ8AAAAAEhHMEQCIAo5RI1TtAoOSjUfHLiBi1rZN7e9v+4cNKfiEjXvaqCYAiAAq/59k9LxVFjf8mkSs7u49wDR127cFd1vLU3bk3vifQH+////XTiaFEkYHocUhIg+XmbMi3nnpSw1qgKYKbZh1oS7dlsAAAAASEcwRAIgc/2/mN/evEi/hBA4JtTw/82mndVSuISAeTcqDQ5yyfQCIADnr/yfLKbOVj3hbqjUwewVu44xRSoBeHt3ptEwB02BAf7///87CVHCCJ4KsgaiAtMhT2h38YkXIqFy9cYDmU/IthPSmgAAAABIRzBEAiAfkNsXRjf7sPjyknV38nY1WLQ4K7oV8iqP+nhI8/jV5gIgDpJCo3VPg2M4GT9uSuDKlp4w6BqDnJsIyGdZ6XRj0SUB/v///wIAdDukCwAAABepFEsXwThN7VG1GmCRX6Vr5sx9ACEghxyLBSoBAAAAF6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAEHFxYAFN0pb6KQE1p8GMMALEHPAgMkU41fAQhrAkcwRAIgWc5jdGVtRpFmnPBm7KcTNojpLTf8pmAWxsHwryBk94YCIDuCOVGw19oCP4Yg5870w8Zz0QCcK6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA=",
  "complete": true
}
</code></pre>

<p>I was happy when I saw complete = true, but then here's what happened:</p>

<pre><code>BITOCW finalizepsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcw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z4FgNBlYt0d28gIgCQbediJ7kTw6Hr94o4I2IiwaD3xHFN8qQI0aNl5Bjh4B/v///zPoBvkyeie1HxFTJRUrG/J7pE67/XCDa8t+uxpZKwQ8AAAAAEhHMEQCIAo5RI1TtAoOSjUfHLiBi1rZN7e9v+4cNKfiEjXvaqCYAiAAq/59k9LxVFjf8mkSs7u49wDR127cFd1vLU3bk3vifQH+////XTiaFEkYHocUhIg+XmbMi3nnpSw1qgKYKbZh1oS7dlsAAAAASEcwRAIgc/2/mN/evEi/hBA4JtTw/82mndVSuISAeTcqDQ5yyfQCIADnr/yfLKbOVj3hbqjUwewVu44xRSoBeHt3ptEwB02BAf7///87CVHCCJ4KsgaiAtMhT2h38YkXIqFy9cYDmU/IthPSmgAAAABIRzBEAiAfkNsXRjf7sPjyknV38nY1WLQ4K7oV8iqP+nhI8/jV5gIgDpJCo3VPg2M4GT9uSuDKlp4w6BqDnJsIyGdZ6XRj0SUB/v///wIAdDukCwAAABepFEsXwThN7VG1GmCRX6Vr5sx9ACEghxyLBSoBAAAAF6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAEHFxYAFN0pb6KQE1p8GMMALEHPAgMkU41fAQhrAkcwRAIgWc5jdGVtRpFmnPBm7KcTNojpLTf8pmAWxsHwryBk94YCIDuCOVGw19oCP4Yg5870w8Zz0QCcK6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA="
error code: -22
error message:
TX decode failed PSBT is not sane.: iostream error
</code></pre>

<p>I found that issue #14473 on github bitcoin project seems to be related to that, but I'm not sure (<a href="https://github.com/bitcoin/bitcoin/issues/14473" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/issues/14473</a>).</p>

<p><strong>[EDIT]</strong>:</p>

<p>About <strong>(2)</strong>: I got <em>scriptPubKey</em> inside the <em>embedded</em> field as suggested, which is <strong>0014dd296fa290135a7c18c3002c41cf020324538d5f</strong>, and also the amount, as it is not in the raw transaction (as advised by Peter):</p>

<pre><code>BITOCW -named signrawtransactionwithkey hexstring=$RAW_TRANSACTION prevtxs='[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"0014dd296fa290135a7c18c3002c41cf020324538d5f", "amount":499.9999}]' privkeys='["cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj"]'
{
  "hex": "02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000",
  "complete": true
}
</code></pre>

<p>Then I can broadcast the signed transaction on online machine, but: </p>

<pre><code>BITVOW sendrawtransaction 02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000
error code: -26
error message: mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)
</code></pre>

<hr>

<p>About the coin selection with <strong>fundrawtransaction</strong>, I created an empty transaction and tried to fund it, from the online "view-only" wallet:</p>

<pre><code>$ BITVOW createrawtransaction '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":1}'02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000
$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true}'
error code: -4
error message:
Insufficient funds
</code></pre>

<p>Is <strong>includeWatching</strong> enough to make it take the watch-only address into account? To be sure, I tried :</p>

<pre><code>$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true, "changeAddress":"2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"}'
</code></pre>

<p>And it made my <em>bitcoind</em> abort with error: </p>

<blockquote>
  <p>2018-10-27T18:55:19Z New outbound peer connected: version: 70015,
  blocks=112, peer=0 bitcoind: policy/feerate.cpp:25: CAmount
  CFeeRate::GetFee(size_t) const: Assertion `nBytes_ &lt;=
  uint64_t(std::numeric_limits::max())' failed. Aborted</p>
</blockquote>

<p>About the coin selection with <strong>walletcreatefundedpsbt</strong>, I gives me:</p>

<pre><code>$ BITVOW walletcreatefundedpsbt '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499}'
error code: -4
error message:
Insufficient funds
</code></pre>

<coldstorage><offline><raw><bip174-psbt>
Signing a bitcoin transaction OFFLINE fails
bitcoinmonkey
# Signing a bitcoin transaction OFFLINE fails

(Asked by: username_0 on 2018-10-26)

I know this subject has been discussed quite a lot, but after several *days* looking for this to work, I give up.

I want to create a transaction on a view-only wallet which is connected to the internet and synced, then sign this transaction on a "cold" offline machine that has the private key, then send this transaction on the view-only wallet.

> View-only wallet will be [VOW]
>
> Offline cold wallet will be [OCW]
>
> Some other bitcoin wallet will be [SOW] (on another 3rd machine, that will play the peer)

First let's simulate the nodes, with one node on each machine:

```
[VOW] bitcoind -regtest -wallet=/path/daemon1.dat -datadir=/path/.bitcoin1 -rpcport=18334 -port=18434 -addnode=127.0.0.1:18435
[SOW] bitcoind -regtest -wallet=/path/daemon2.dat -datadir=/path/.bitcoin2 -rpcport=18335 -port=18435 -addnode=127.0.0.1:18434
[OCW] bitcoind -regtest  -datadir=/path2/.bitcoin -wallet=/path2/wallet -rpcport=18336 -port=18436

```

With these aliases to call the bitcoin-cli:

```
alias BITVOW='bitcoin-cli -regtest -datadir=/path/.bitcoin1 -rpcport=18334'
alias BITSOW='bitcoin-cli -regtest -datadir=/path/.bitcoin2 -rpcport=18335'
alias BITOCW='bitcoin-cli -regtest -rpcport=18336'

```

So the two [VOW] and [SCW] connect to each other, no problem with that (they form a small 2 nodes network).

On the offline machine, I do this:

```
$ BITOCW getnewaddress
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITOCW dumpprivkey
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj

```

I want to send 500 BTC to **2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL**, so I generate funds to the "other" wallet, to pay my wallet, with a generate to validate the transaction:

```
$ BITSOW generate X
$ BITSOW getbalance
550.00000000
$ BITSOW sendtoaddress 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL 500
33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1
$ BITSOW generate 1
$ BITSOW getnewaddress
2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM

```

I will use this address **2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM** to receive funds from my main wallet with an offline signature.

I import the bitcoin address on a wallet-view wallet, and check the balance:

```
$ BITVOW importaddress  2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITVOW getbalance "*" 0 true
500.00000000

```

Perfect. Now comes the part where I want to send thoses 500 back to **2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM** using an offline transaction signing.

First let's identify the TX that can be used:

```
$ BITVOW listunspent 1 99999999 '["2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"]'
[
  {
    "txid": 
    "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
    "vout": 0,
    "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
    "label": "",
    "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
    "amount": 500.00000000,
    "confirmations": 1,
    "spendable": false,
    "solvable": false,
    "safe": true
  }
]
$ BITVOW createrawtransaction '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499.9999}'

```

This gets as a raw transaction (that I put in $RAW\_TRANSACTION for example):

> 0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000

Then, on the offline machine, I want to sign this using the private key:

```
$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION
{
    "hex": "0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000",
    "complete": false,
    "errors": [
   {
   "txid": "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
  "vout": 0,
  "witness": [
  ],
  "scriptSig": "",
  "sequence": 4294967295,
  "error": "Input not found or already spent"
}
]
}

```

Thank you very much for your help!

**[EDIT]**:I also tried this:

```
$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]'
error code: -3
error message:
Missing amount for CTxOut(nValue=21000000.00000000, scriptPubKey=a9144b17c1384ded51b51a60915fa5)

```

**[EDIT]**

Here is what I tried using the provided solutions (2) and (3) from *username_1 username_1*:

**(2)**
I tried this on the offline system [OCW], in order to get RedeemScript for the signing process:

```
BITOCW getaddressinfo 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL{
  "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
  "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
  "ismine": true,
  "iswatchonly": false,
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_keyhash",
  "hex": "0014dd296fa290135a7c18c3002c41cf020324538d5f",
  "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
  "embedded": {
    "isscript": false,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "dd296fa290135a7c18c3002c41cf020324538d5f",
    "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
    "address": "bcrt1qm55klg5szdd8cxxrqqkyrnczqvj98r2l8m5l0f",
    "scriptPubKey": "0014dd296fa290135a7c18c3002c41cf020324538d5f"
  },
  "label": "",
  "timestamp": 1540018166,
  "hdkeypath": "m/0'/0'/4'",
  "hdseedid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
  "hdmasterkeyid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
  "labels": [
    {
      "name": "",
      "purpose": "receive"
    }
  ]
}

```

Maybe I am missing something, but I could not find a proper RedeemScript for signing.

**(3)**
First of all, I didn't know it was possible to do such a thing without doing the coin selection myself. If it is, I'd rather have the "online watch-only" wallet make the coin selection automatically so that I don't have to programmatically select the suitable inputs.

Then, following your advice, this is what i've tried so far, after the same **createrawtransaction** as above, on the online system:

```
BITVOW converttopsbt 0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000
cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==

```

And:

```
BITVOW walletprocesspsbt cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==
{
  "psbt": "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbtEbzL8i2dzUFq8RcAAAAASEcwRAIgVoSlc5RumxBU/O4gDzrFdXcxuCBDt30DczglDmuvSegCIFkZIqu1OS5UNncEThnNS8th+38lFf71PDa9Og2n3TKFAf7////Zq7QRMc7AhtcyGYE/HdvSAR146Dv659BXuzrHycdrcQAA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v4tHeqBx1H6HbwAAAAAA",
  "complete": false
}

```

Then I exported this on the offline system and did:

```
BITOCW  walletprocesspsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbtEbzL8i2dzUFq8RcAAAAASEcwRAIgVoSlc5RumxBU/O4gDzrFdXcxuCBDt30DczglDmuvSegCIFkZIqu1OS5UNncEThnNS8th+38lFf71PDa9Og2n3TKFAf7////Zq7QRMc7AhtcyGYE/HdvSAR146Dv659BXuzrHycdrcQAAAABIRzBEAiBctxeVGCoN8zlKnG19Tgs4GKnQ1r/Ge6Hjr/kIX0LJSQIgNHhYFpt2aabQEWA06apQpTcscoBH1hkDO9b9P3kNBKsB/v///0dInKhhB5SbX3zsU4+I8irL8UFXYDWqM2njZ8cDJQw4AAAAAEhHMEQCIEy0Fm9FwnEMSm6Cx37tMs8VFKNWypz3iXDZGinXpoGLAiAtH98TAw71JPde6+85VXuy5iuFa1AHt+wkF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r94o4I2IiwaD3xHFN8qQI0aNl5Bjh4B/v///zPoBvkyeie1HxFTJRUrG/J7pE67/XCDa8t+uxpZKwQ8AAAAAEhHMEQCIAo5RI1TtAoOSjUfHLiBi1rZN7e9v+4cNKfiEjXvaqCYAiAAq/59k9LxVFjf8mkSs7u49wDR127cFd1vLU3bk3vifQH+////XTiaFEkYHocUhIg+XmbMi3nnpSw1qgKYKbZh1oS7dlsAAAAASEcwRAIgc/2/mN/evEi/hBA4JtTw/82mndVSuISAeTcqDQ5yyfQCIADnr/yfLKbOVj3hbqjUwewVu44xRSoBeHt3ptEwB02BAf7///87CVHCCJ4KsgaiAtMhT2h38YkXIqFy9cYDmU/IthPSmgAAAABIRzBEAiAfkNsXRjf7sPjyknV38nY1WLQ4K7oV8iqP+nhI8/jV5gIgDpJCo3VPg2M4GT9uSuDKlp4w6BqDnJsIyGdZ6XRj0SUB/v///wIAdDukCwAAABepFEsXwThN7VG1GmCRX6Vr5sx9ACEghxyLBSoBAAAAF6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAEHFxYAFN0pb6KQE1p8GMMALEHPAgMkU41fAQhrAkcwRAIgWc5jdGVtRpFmnPBm7KcTNojpLTf8pmAWxsHwryBk94YCIDuCOVGw19oCP4Yg5870w8Zz0QCcK6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA=",
  "complete": true
}

```

I was happy when I saw complete = true, but then here's what happened:

```
BITOCW finalizepsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFF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aNl5Bjh4B/v///zPoBvkyeie1HxFTJRUrG/J7pE67/XCDa8t+uxpZKwQ8AAAAAEhHMEQCIAo5RI1TtAoOSjUfHLiBi1rZN7e9v+4cNKfiEjXvaqCYAiAAq/59k9LxVFjf8mkSs7u49wDR127cFd1vLU3bk3vifQH+////XTiaFEkYHocUhIg+XmbMi3nnpSw1qgKYKbZh1oS7dlsAAAAASEcwRAIgc/2/mN/evEi/hBA4JtTw/82mndVSuISAeTcqDQ5yyfQCIADnr/yfLKbOVj3hbqjUwewVu44xRSoBeHt3ptEwB02BAf7///87CVHCCJ4KsgaiAtMhT2h38YkXIqFy9cYDmU/IthPSmgAAAABIRzBEAiAfkNsXRjf7sPjyknV38nY1WLQ4K7oV8iqP+nhI8/jV5gIgDpJCo3VPg2M4GT9uSuDKlp4w6BqDnJsIyGdZ6XRj0SUB/v///wIAdDukCwAAABepFEsXwThN7VG1GmCRX6Vr5sx9ACEghxyLBSoBAAAAF6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAEHFxYAFN0pb6KQE1p8GMMALEHPAgMkU41fAQhrAkcwRAIgWc5jdGVtRpFmnPBm7KcTNojpLTf8pmAWxsHwryBk94YCIDuCOVGw19oCP4Yg5870w8Zz0QCcK6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA="
error code: -22
error message:
TX decode failed PSBT is not sane.: iostream error

```

I found that issue #14473 on github bitcoin project seems to be related to that, but I'm not sure (<https://github.com/bitcoin/bitcoin/issues/14473>).

**[EDIT]**:

About **(2)**: I got *scriptPubKey* inside the *embedded* field as suggested, which is **0014dd296fa290135a7c18c3002c41cf020324538d5f**, and also the amount, as it is not in the raw transaction (as advised by Peter):

```
BITOCW -named signrawtransactionwithkey hexstring=$RAW_TRANSACTION prevtxs='[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"0014dd296fa290135a7c18c3002c41cf020324538d5f", "amount":499.9999}]' privkeys='["cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj"]'
{
  "hex": "02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000",
  "complete": true
}

```

Then I can broadcast the signed transaction on online machine, but:

```
BITVOW sendrawtransaction 02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000
error code: -26
error message: mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)

```

---

About the coin selection with **fundrawtransaction**, I created an empty transaction and tried to fund it, from the online "view-only" wallet:

```
$ BITVOW createrawtransaction '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":1}'02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000
$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true}'
error code: -4
error message:
Insufficient funds

```

Is **includeWatching** enough to make it take the watch-only address into account? To be sure, I tried :

```
$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true, "changeAddress":"2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"}'

```

And it made my *bitcoind* abort with error:

> 2018-10-27T18:55:19Z New outbound peer connected: version: 70015,
> blocks=112, peer=0 bitcoind: policy/feerate.cpp:25: CAmount
> CFeeRate::GetFee(size\_t) const: Assertion `nBytes\_ <=
> uint64\_t(std::numeric\_limits::max())' failed. Aborted

About the coin selection with **walletcreatefundedpsbt**, I gives me:

```
$ BITVOW walletcreatefundedpsbt '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499}'
error code: -4
error message:
Insufficient funds

```

**Tags:** coldstorage, offline, raw, bip174-psbt


---

## 3 answers

### Answer by username_1 on 2018-10-26. Score: 5

`signrawtransactionwithwallet` uses the wallet for two purposes:

* Finding the private keys necessary to sign with (which you dealt with by importing)
* Finding the transaction outputs that are being spent (without this information you can't construct a valid transaction, and the offline wallet, being offline, does not have access to the transactions that credited you).

There are a number of solutions for this, in order of increasing practicality:

* Copy the wallet.dat from the online system to the offline system, so it sees the transaction history (do not transfer it back, as it will contain private keys)
* Use the `signrawtransactionwithkey` RPC, which lets you specify the private key and the UTXO information in the RPC call, so no importing is needed anymore on the offline system.
* Use the PSBT style RPC calls; use `walletcreatefundedpsbt` on the offline system, sign it on the online system using `walletprocesspsbt`, extract a finished transaction using `finalizepsbt`, which you can broadcast using `sendrawtransaction`. The PSBT files contain all metadata needed for signing, including the old transaction (outputs) being spent.

> **Comments:**
> **username_0**: Thank you for your quick and precise answer. About **solution 2** : I tried this before, and _signrawtransactionwithkey_ gives me error code: -3 = "Missing redeemScript". About **solution 3**, which I didn't know at all, _walletcreatefundedpsbt_ gives me "Insufficient funds" error.  
> **username_1**: About (2): If you're spending from a P2SH address you also need to provide `signrawtransactionwithkey` with the redeemScript (can be found using `getaddressinfo`). PSBT also stores this information directly.  
> **username_1**: About (3), sorry my advice was bad as you're doing the coin selection yourself. You can use `createrawtransaction` like you're doing now, then call `converttopsbt` on the result, then call `walletprocesspsbt` on the online system (which will add redeemscript and UTXO information), and then `walletprocesspsbt` on the offline system to sign, followed by `finalizepsbt` and `sendrawtransaction`. If this works I'll update my answer.  
> **username_0**: Thanks again username_1, I just edited my question to allow a more precise output, as I could not get that to work.  
> **username_1**: About (2), what you need is the "scriptPubKey" inside the "embedded" field; it gives the script that's wrapped in P2SH. Without it, the signer doesn't know what you're actually trying to sign (as it's only given a hash of the script).  
> **username_1**: About (3) that indeed looks like a bug; it will presumably be fixed in the 0.17.1 release.  
> **username_1**: Also, if you don't want to do coin selection yourself, you can use the `fundrawtransaction` or `walletcreatefundedpsbt` RPCs. You feed them the output you want to send, and these RPcs will add inputs and change from your wallet as necessary.  
> **username_0**: Thank you again. I updated the original post with what you suggested. Unfortunately, I could not achieve the "automatic coin selection" even after I read your answer to (https://bitcoin.stackexchange.com/questions/58920/what-is-a-workaround-to-fundrawtransaction-for-watchonly-addresses). The solution you provided with (2) did not work for me (missing amount), which is strange because amount is apparently specified in the raw transaction.  
> **username_0**: (https://github.com/bitcoin/bitcoin/issues/14401) seems to be related to the abort of the bitcoind by the way  
> **username_1**: `signrawtransactionwithkey` needs to know the amounts of the *inputs* you're signing; this information is not part of the raw transaction. You find the amounts in the listunspent output, and need to pass it in along with the UTXOs being spent.  
> **username_0**: Sorry but I could not make it work, with any of the solutions proposed. I'll just wait for a next bitcoin-core release to see if it works better.  
> **username_2**: Peter's solution (3) works with v0.18.1 given the steps he detailed in the third comment.  

---

### Answer by username_3 on 2020-09-02. Score: 1

I have a very old Greg Maxwell tutorial for this slightly old question  
[https://web.archive.org/web/20171124193914/https://people.xiph.org/~greg/signdemo.txt](https://web.archive.org/web/20171124193914/https://people.xiph.org/%7Egreg/signdemo.txt)  
The tutorial uses 'bitcoind' as the command because it was written before 'bitcoin-cli' became the correct command. Apart from this detail, the tutorial should still work with a recent Bitcoin Core version

I'm not sure why this discussion diverged to "PSBT does this better" without answering the question that was written, but I won't argue against "PSBT does this better"

The question is now hard to follow, has been altered in a train of thought manner, so it's possible I missed something

The question uses 'signrawtransactionwithwallet'  
The tutorial uses 'signrawtransaction'

The questioner tries to use 'getaddressinfo' to find the RedeemScript  
The tutorial uses 'decoderawtransaction' to expose the RedeemScript

Unless I'm reading the flow of advice incorrectly, the problem is that a cold wallet can not know the RedeemScript, and this is why 'signrawtransactionwithwallet' fails to work. 'signrawtransaction' accepts the RedeemScript as a parameter, and 'decoderawtransaction' exposes the RedeemScript

I haven't tried the method in the Greg Maxwell tutorial, but I hope this small contribution is useful to understanding the problem better

If I cannot find a newer offline signing tutorial, I will try to put aside some time to write a fresh version


---

### Answer by username_4 on 2019-07-05. Score: 0

I do not have enough reputation to reply on username_1 username_1's answer, but I have tested using PSBT (solution 3) with bitcoin-core v0.18.0, it now works well for this. In my case, using PSBT was a lot easier than using `signrawtransactionwithkey`. The steps I've used are:

1. `createrawtransaction` on watch-only wallet.
2. `fundrawtransaction` on watch-only wallet.
3. `converttopsbt` on watch-only wallet.
4. `walletprocesspsbt` on watch-only wallet. Not sure why this is necessary but it does change the PSBT string. I thought `converttopsbt` would do whatever this step does.
5. `walletprocesspsbt` on offline wallet.
6. `finalizepsbt` on offline wallet.

It shouldn't make a difference, but for the record I've used the RPC API, not the command-line.

> **Comments:**
> **username_2**: I think step 5 should be done on offline wallet.  
> **username_2**: The reason why step 4 is needed, is because the inputs are referenced by `txid:vout` and the offline wallet cannot know how to get the details needed (e.g. `scriptPubKey`) since it doesn't have any blocks. So `walletprocesspsbt` on the watch-only (onlline) wallet fills in this information (in particular the psbt's `inputs[]` part).  
> **username_4**: @ThalisK. You're right, sorry for the typo ! And about step 4, I understand that and agree, but I don't see why step 3 isn't already doing this. But anyway, it's not a problem to do it in two steps.  
> **username_2**: As far as I understand `converttopsbt` literally does the conversion from one structure format (tx) to the other (psbt). It doesn't do lookup and filling in of data. `walletprocesspsbt` does the lookup and filling in. Separation of concerns keeps each command simple and focused.  

---

