user-1: What are the steps that we can follow to create an unsigned tx for watch-only cold storage address using bitcoin core? How can we sign the transaction and broadcast it later?

user-1: 

Run the below commands in electrum console:


>> getaddresshistory('tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd')
[
    {
        "height": 1807710,
        "tx_hash": "727707cced87f9bc2a1ca3ed28df39588e9881fd50c272e78bc76a5bb1ffde9c"
    }
]
>> deserialize(gettransaction('727707cced87f9bc2a1ca3ed28df39588e9881fd50c272e78bc76a5bb1ffde9c'))
{
    "inputs": [
        {
            "coinbase": false,
            "nsequence": 4294967295,
            "prevout_hash": "99ebe2d047c545a50cf86f0ff5f4c0648437cb8724137f1a33c2f06eb06ef35a",
            "prevout_n": 1,
            "scriptSig": "",
            "witness": "0247304402206379d344d75fbee07f54213378f95e44dc757872d59a35efbc14ec7e1ca7dfd102207a47f9c1be39cafa8f9ac8a879e2b968e2359bead23a1f6598478ed7d141c73d012103ee169045615c663c0204472f86e3c2b2ae43e574146d30607c42fe6d670ac7be"
        }
    ],
    "locktime": 0,
    "outputs": [
        {
            "address": "tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd",
            "scriptpubkey": "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5",
            "value_sats": 3000000
        },
        {
            "address": "tb1q7sx47sra5w7kw8we5xeusl4089ryverhjcft6q",
            "scriptpubkey": "0014f40d5f407da3bd671dd9a1b3c87eaf3946466477",
            "value_sats": 61797954
        }
    ],
    "version": 2
}

You get the scriptPubKey in above output which can be used in importmulti command in bitcoin core:
"address": "tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd",
"scriptpubkey": "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5"
Get the public key of the address from details:

If you are using bitcoin core wallet instead of electrum in this example, you can run the getaddressinfo command in console to get scriptPubKey and pubkey of the address.
Run the below command in bitcoin core console to import the address with the details copied from electrum:
importmulti '[{"scriptPubKey" : "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5","pubkeys" : ["0304c5184085eea27a072628de03fbb953f5fdd99fb526f097fdd4c6968d165f1a"],"timestamp" : "now","label" : "watch-address-test", "watchonly": true}
You can ignore the steps mentioned above for scriptPubKey and only use the "Public Key" of an address by using descriptor:
We need checksum in importmulti which is returned in descriptorinfo for the public key mentioned

Next, we can run importmulti command (I have used public key for a different address in this command):

importmulti '[{"desc" : "wpkh(026641b79d7ffa40ddf994f0277c2649f3ddcbd871194ba6ef87687daea22ca503)#zl4yt8hu","timestamp" : "now","label" : "watch-address-test", "watchonly": true}]'


rescanblockchain 1800000 1835099
I can see available inputs in GUI:

We still get an error if trying to create an unsigned tx which involves sending some amount to change address because we aren't trying to spend the whole balance.

Add a change address for creating unsigned tx:

Option to copy PSBT:

Load transaction using the copied text in electrum:


Copy the hex of signed tx and run the below command in bitcoin core:


sendrawtransaction 020000000001019cdeffb15b6ac78be772c250fd81988e5839df28eda31c2abcf987edcc0777720000000000fdffffff02b3410f0000000000160014112c8ecb9e0876a645e7b8e89eed83bd61096e2c80841e00000000001600145f24e8fbfe65840c27dad3b053855de4cee843820247304402200d7cc29a8588c180e6a460e0eb88ea830db76dbb040a875d45fe8c64c9509a80022060879365af1c6d19e7c47bdbfa402a053ed42809c52db6816cd249dff46529b001210304c5184085eea27a072628de03fbb953f5fdd99fb526f097fdd4c6968d165f1a5f001c00


It returns the transaction id: 4890c14e7635a3e72320046645686052339e443eba56e5a62849a48b3f67f419
You can check the details in a block explorer: https://blockstream.info/testnet/tx/4890c14e7635a3e72320046645686052339e443eba56e5a62849a48b3f67f419
Related questions:
How to create unsigned tx in a watch-only wallet?
How to move/sweep your Bitcoin Core bitcoins safely and air-gapped to your new fancy cold storage?
Related issues:
https://github.com/bitcoin-core/gui/issues/94

-1: <p>What are the steps that we can follow to create an unsigned tx for watch-only cold storage address using bitcoin core? How can we sign the transaction and broadcast it later?</p>
 -1: <p><a href="https://i.stack.imgur.com/pNDyC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pNDyC.png" alt="create wallet" /></a></p>
<p><a href="https://i.stack.imgur.com/0fPiO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0fPiO.png" alt="cold-storage-example" /></a></p>
<p>Run the below commands in electrum console:</p>
<pre><code>

>> getaddresshistory('tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd')
[
    {
        "height": 1807710,
        "tx_hash": "727707cced87f9bc2a1ca3ed28df39588e9881fd50c272e78bc76a5bb1ffde9c"
    }
]
>> deserialize(gettransaction('727707cced87f9bc2a1ca3ed28df39588e9881fd50c272e78bc76a5bb1ffde9c'))
{
    "inputs": [
        {
            "coinbase": false,
            "nsequence": 4294967295,
            "prevout_hash": "99ebe2d047c545a50cf86f0ff5f4c0648437cb8724137f1a33c2f06eb06ef35a",
            "prevout_n": 1,
            "scriptSig": "",
            "witness": "0247304402206379d344d75fbee07f54213378f95e44dc757872d59a35efbc14ec7e1ca7dfd102207a47f9c1be39cafa8f9ac8a879e2b968e2359bead23a1f6598478ed7d141c73d012103ee169045615c663c0204472f86e3c2b2ae43e574146d30607c42fe6d670ac7be"
        }
    ],
    "locktime": 0,
    "outputs": [
        {
            "address": "tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd",
            "scriptpubkey": "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5",
            "value_sats": 3000000
        },
        {
            "address": "tb1q7sx47sra5w7kw8we5xeusl4089ryverhjcft6q",
            "scriptpubkey": "0014f40d5f407da3bd671dd9a1b3c87eaf3946466477",
            "value_sats": 61797954
        }
    ],
    "version": 2
}
</pre></code>
<p>You get the scriptPubKey in above output which can be used in <code>importmulti</code> command in bitcoin core:</p>
<pre><code>"address": "tb1qu2l4n8st9w3hhsxstd8muaxgnu63fql9rkylmd",
"scriptpubkey": "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5"</pre></code>
<p>Get the public key of the address from details:</p>
<p><a href="https://i.stack.imgur.com/XA5Jf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XA5Jf.png" alt="address-details-electrum" /></a></p>
<p>If you are using bitcoin core wallet instead of electrum in this example, you can run the <code>getaddressinfo</code> command in console to get <code>scriptPubKey</code> and <code>pubkey</code> of the address.</p>
<p>Run the below command in bitcoin core console to import the address with the details copied from electrum:</p>
<pre><code>importmulti '[{"scriptPubKey" : "0014e2bf599e0b2ba37bc0d05b4fbe74c89f351483e5","pubkeys" : ["0304c5184085eea27a072628de03fbb953f5fdd99fb526f097fdd4c6968d165f1a"],"timestamp" : "now","label" : "watch-address-test", "watchonly": true}</pre></code>
<p><strong>You can ignore the steps mentioned above for scriptPubKey and only use the &quot;Public Key&quot; of an address by using <a href="https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md" rel="nofollow noreferrer">descriptor</a>:</strong></p>
<p>We need checksum in <code>importmulti</code> which is returned in <code>descriptorinfo</code> for the public key mentioned</p>
<p><a href="https://i.stack.imgur.com/wlKVi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wlKVi.png" alt="descriptorinfo" /></a></p>
<p>Next, we can run <code>importmulti</code> command (I have used public key for a different address in this command):</p>
<pre><code>
importmulti '[{"desc" : "wpkh(026641b79d7ffa40ddf994f0277c2649f3ddcbd871194ba6ef87687daea22ca503)#zl4yt8hu","timestamp" : "now","label" : "watch-address-test", "watchonly": true}]'
</pre></code>
<p><a href="https://i.stack.imgur.com/nxq9Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nxq9Y.png" alt="receiving-address" /></a></p>
<pre><code>rescanblockchain 1800000 1835099</pre></code>
<p>I can see available inputs in GUI:</p>
<p><a href="https://i.stack.imgur.com/N7iRL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N7iRL.png" alt="inputs" /></a></p>
<p>We still get an error if trying to create an unsigned tx which involves sending some amount to change address because we aren't trying to spend the whole balance.</p>
<p><a href="https://i.stack.imgur.com/d6keN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d6keN.png" alt="change-error" /></a></p>
<p>Add a change address for creating unsigned tx:</p>
<p><a href="https://i.stack.imgur.com/Uaycz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uaycz.png" alt="add-change-address" /></a></p>
<p>Option to copy PSBT:</p>
<p><a href="https://i.stack.imgur.com/O6HDv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O6HDv.png" alt="PSBT" /></a></p>
<p>Load transaction using the copied text in electrum:</p>
<p><a href="https://i.stack.imgur.com/OwS02.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OwS02.png" alt="load-tx" /></a></p>
<p><a href="https://i.stack.imgur.com/GPlsx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GPlsx.png" alt="sign-tx" /></a></p>
<p>Copy the hex of signed tx and run the below command in bitcoin core:</p>
<pre><code>

sendrawtransaction 020000000001019cdeffb15b6ac78be772c250fd81988e5839df28eda31c2abcf987edcc0777720000000000fdffffff02b3410f0000000000160014112c8ecb9e0876a645e7b8e89eed83bd61096e2c80841e00000000001600145f24e8fbfe65840c27dad3b053855de4cee843820247304402200d7cc29a8588c180e6a460e0eb88ea830db76dbb040a875d45fe8c64c9509a80022060879365af1c6d19e7c47bdbfa402a053ed42809c52db6816cd249dff46529b001210304c5184085eea27a072628de03fbb953f5fdd99fb526f097fdd4c6968d165f1a5f001c00

</pre></code>
<p><strong>It returns the transaction id:</strong> <code>4890c14e7635a3e72320046645686052339e443eba56e5a62849a48b3f67f419</code></p>
<p>You can check the details in a block explorer: <strong><a href="https://blockstream.info/testnet/tx/4890c14e7635a3e72320046645686052339e443eba56e5a62849a48b3f67f419" rel="nofollow noreferrer">https://blockstream.info/testnet/tx/4890c14e7635a3e72320046645686052339e443eba56e5a62849a48b3f67f419</a></strong></p>
<p><em>Related questions:</em></p>
<p><a href="https://bitcoin.stackexchange.com/questions/99046/how-to-create-unsigned-tx-in-a-watch-only-wallet">How to create unsigned tx in a watch-only wallet?</a></p>
<p><a href="https://bitcoin.stackexchange.com/questions/98715/how-to-move-sweep-your-bitcoin-core-bitcoins-safely-and-air-gapped-to-your-new-f">How to move/sweep your Bitcoin Core bitcoins safely and air-gapped to your new fancy cold storage?</a></p>
<p><em>Related issues:</em>
<a href="https://github.com/bitcoin-core/gui/issues/94" rel="nofollow noreferrer">https://github.com/bitcoin-core/gui/issues/94</a></p>
