Signing a bitcoin transaction OFFLINE fails

Signing a bitcoin transaction OFFLINE fails

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"}]' '{"2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL":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!

https://ift.tt/2JgN5G3

Comments

Popular posts from this blog

Bitcoin Core errors with database block

sendrawtransaction and txn-mempool-conflict