Bitcoin Forum
January 23, 2020, 10:35:41 AM *
News: Latest Bitcoin Core release: 0.19.0.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to sign an Unsigned RawTx from 2-of-3 Multi-Sig Address using Bitcoin Core?  (Read 306 times)
100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
September 28, 2019, 07:22:18 PM
 #1

The actual problem is not for BTC, but for BCD. But, I believe, the solution will be same.

I have some BCD stuck at a 2-of-3 Multi-Sig Address for a long time. So far, I have tried out almost all the wallets that support BCD, except for QT or Core wallet. None of the BCD wallets support signing an unsigned rawtx from 2-of-3 multi-sig address using private keys only (Electrum thread - https://bitcointalk.org/index.php?topic=5169272.0). All of them require xPriv key, which I dont know. Hence, I am now trying to sign with Bitcoin Diamond QT or Core wallet downloaded from https://github.com/eveybcd/BitcoinDiamond/releases/download/v1.3.0/bitcoindiamond-1.3.0-win64-setup-unsigned.exe.

So, here is what I have...

1. 2-of-3 Multi-Sig Address

2. Redeem Script

3. 3 different private keys

4. Unsigned RawTx to a legacy BTC/BCD address

I need to sign using QT or Core without downloading the complete blockchain data. Because, my purpose is not to run a full node, but to sign and broadcast a transaction.

How do I do so?

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
Dabs
Legendary
*
Offline Offline

Activity: 2576
Merit: 1352


The Concierge of Crypto


View Profile
September 29, 2019, 01:47:58 AM
 #2

Not sure if it will help, but you could try coinb.in ...

If that doesn't work or help, then your last resort would be to run the full node and grab the whole blockchain long enough to import the private keys, sign, and broadcast the transaction.

nc50lc
Hero Member
*****
Online Online

Activity: 840
Merit: 905


Self-proclaimed Genius ㊙️


View Profile WWW
September 29, 2019, 02:46:45 AM
 #3

Not sure if it will help, but you could try coinb.in ...
It will work for Bitcoin,
but unfortunately, there's no altcoin version of coinb.in.

@100bitcoin Electrum won't work since it's currently impossible to import the redeem script of an imported multisig address.
Importing the address won't do.

Hence, I am now trying to sign with Bitcoin Diamond QT or Core wallet downloaded from https://github.com/eveybcd/BitcoinDiamond/releases/download/v1.3.0/bitcoindiamond-1.3.0-win64-setup-unsigned.exe.
If it's based from Bitcoin Core client, addmultisigaddress and signrawtransaction commands might work but requires you to sync the client.
Refer to the link for the syntax.

signrawtransaction to that "unsigned raw tx" might work without a full synced client if it contains the redeem script.
You can also manually create a raw tx using the console but it requires manual addition of the info... <-haven't tried this though.

pooya87
Legendary
*
Online Online

Activity: 1890
Merit: 2266


Remember tonight for it's the beginning of forever


View Profile
September 29, 2019, 04:27:47 AM
Merited by dbshck (4), ETFbitcoin (1)
 #4

try combining the two methods: coinb.in with core client while using a BCD block explorer. that way you don't need to sync anything.

- open a BCD block explorer and search your address to get the list of transactions. now you have to figure out if each received tx is spent or not, explorers usually have some sort of indicator for that. if it weren't then copy its txid and the index of your address among the outputs of that transaction (eg. if the tx is paying you and your address is the first one your index is 0, if your address is the fifth one then your index is 4)*
- select inputs tab and set txid and N value. (leave script and amount empty)
- select output tab and insert your address and amount, you may need to convert your address here if BCD uses a different address encoding like a different version byte (if it does let me know to explain how to do that)
- click submit and get the raw transaction and transfer that to core client
- use the signrawtransaction command to sign it with your list of keys.

* a random example from last block:
https://www.blockchain.com/btc/tx/7f3298d222478f9ad2eae0e44dca57c32f6a5461c87555caf77e1954d05197f5
assuming 3CrHefYE5ZnMEeedXxKZbU8icQVkc93rPD is your address hypothetically, the txid is 7f3298d222478f9ad2eae0e44dca57c32f6a5461c87555caf77e1954d05197f5 and N (or index) is 7

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
September 29, 2019, 08:42:29 PM
 #5

- open a BCD block explorer and search your address to get the list of transactions. now you have to figure out if each received tx is spent or not, explorers usually have some sort of indicator for that. if it weren't then copy its txid and the index of your address among the outputs of that transaction (eg. if the tx is paying you and your address is the first one your index is 0, if your address is the fifth one then your index is 4)*
- select inputs tab and set txid and N value. (leave script and amount empty)
- select output tab and insert your address and amount, you may need to convert your address here if BCD uses a different address encoding like a different version byte (if it does let me know to explain how to do that)
- click submit and get the raw transaction and transfer that to core client
I have already done this through Electrum for BCD. As I mentioned in OP, I already have an Unsigned RawTx to a legacy BCD address, which is accessible through Electrum for BCD.

- use the signrawtransaction command to sign it with your list of keys.
How do I do this part using QT for BCD without syncing the whole blockchain? I really dont trust the BCD nodes.

pooya87
Legendary
*
Online Online

Activity: 1890
Merit: 2266


Remember tonight for it's the beginning of forever


View Profile
September 30, 2019, 04:37:16 AM
 #6

- use the signrawtransaction command to sign it with your list of keys.
How do I do this part using QT for BCD without syncing the whole blockchain? I really dont trust the BCD nodes.

i have not tested this command but try using this:
Code:
signrawtransactionwithkey "rawtxhex" ["privatekey1","privatekey2"] ( [{"txid":"id","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}] )

replace "rawtxhex" with your raw transaction hex,
"privatekey1" and 2 are the keys to sign the transaction (if it didn't work try using 1 key at a time and do the whole thing twice but the second time use the result from previous step)
"id" is the txid you are spending
n is the index i explained above
pubScrHex is your P2SH script (your address converted to its script form)
redeemhex is your redeem script

ref: https://bitcoincore.org/en/doc/0.18.0/rpc/rawtransactions/signrawtransactionwithkey/

sowns
Jr. Member
*
Offline Offline

Activity: 69
Merit: 3


View Profile
September 30, 2019, 06:32:15 PM
 #7

Multisig addresses start with three right? Then unless I somehow did it wrong then you're out of luck with using bitcoin core since they don't sign 3s apparently. I get the "entered address does not refer to a key" error when I tried.
HCP
Legendary
*
Offline Offline

Activity: 1218
Merit: 2167

<insert witty quote here>


View Profile
September 30, 2019, 11:45:53 PM
Merited by dbshck (4)
 #8

Fairly sure I've done exactly this for several people (but for Bitcoin Gold) who had fork coins "stuck" in multisig (or Electrum 2FA) wallets.

I vaguely recall that you needed to have a synced "core" node to be able to do this... or at least, a node that was synced up to the point where the UTXOs that you were attempting to spend were created. Then it is simply a matter of creating the raw unsigned transaction from those UTXOs... then signing the transaction with at least 2 of the 3 private keys... then broadcasting the transaction.

There should be some old posts floating around somewhere with a bit of a guide on how to do it... I'll have a dig around and see if I can find them.


EDIT: Here you go... have a read through this: https://bitcointalk.org/index.php?topic=2550529.0

It's for BTG, but the same should apply for BCD... again, as noted in the OP in that thread, you will need the "core" node fully synced.

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
October 02, 2019, 07:44:19 PM
 #9

- use the signrawtransaction command to sign it with your list of keys.
How do I do this part using QT for BCD without syncing the whole blockchain? I really dont trust the BCD nodes.

i have not tested this command but try using this:
Code:
signrawtransactionwithkey "rawtxhex" ["privatekey1","privatekey2"] ( [{"txid":"id","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}] )

replace "rawtxhex" with your raw transaction hex,
"privatekey1" and 2 are the keys to sign the transaction (if it didn't work try using 1 key at a time and do the whole thing twice but the second time use the result from previous step)
"id" is the txid you are spending
n is the index i explained above
pubScrHex is your P2SH script (your address converted to its script form)
redeemhex is your redeem script

ref: https://bitcoincore.org/en/doc/0.18.0/rpc/rawtransactions/signrawtransactionwithkey/
Thanks. What would be the "scriptPubKey" for my address? I mean, how do I get to know that?


Fairly sure I've done exactly this for several people (but for Bitcoin Gold) who had fork coins "stuck" in multisig (or Electrum 2FA) wallets.

I vaguely recall that you needed to have a synced "core" node to be able to do this... or at least, a node that was synced up to the point where the UTXOs that you were attempting to spend were created. Then it is simply a matter of creating the raw unsigned transaction from those UTXOs... then signing the transaction with at least 2 of the 3 private keys... then broadcasting the transaction.

There should be some old posts floating around somewhere with a bit of a guide on how to do it... I'll have a dig around and see if I can find them.


EDIT: Here you go... have a read through this: https://bitcointalk.org/index.php?topic=2550529.0

It's for BTG, but the same should apply for BCD... again, as noted in the OP in that thread, you will need the "core" node fully synced.
Thanks. But, this wont work for me. As I mentioned in OP, I dont know my xPriv keys. Though, for BTG, there is a Coinb.in fork, which works like charm only with private keys.

HCP
Legendary
*
Offline Offline

Activity: 1218
Merit: 2167

<insert witty quote here>


View Profile
October 02, 2019, 11:00:10 PM
 #10

Thanks. But, this wont work for me. As I mentioned in OP, I dont know my xPriv keys. Though, for BTG, there is a Coinb.in fork, which works like charm only with private keys.
It will work... as Bitcoin Gold Core doesn't work with xpriv keys anyway... you need the individual private keys. If you read the guide, you see that they just use the xprivs (with iancoleman's BIP39 tool) to convert to the necessary private keys.

So you can skip down the guide to the bit AFTER the xprivs are converted to private keys... somewhere around here:
...
Now we really have everything to start to sign the transaction.

Open Electrum, select “View”->”Show console”.

Run this command:
Code:
deserialize(gettransaction("TXID_HERE"))
Replace TXID_HERE with the transaction ID (leave the “ “)

You will get something like this: https://i.imgur.com/sKXBZNm.png
Go to the section in the bottom with where it says: "address": "our address",

Ok, now copy all that thing in the note at the bottom.
Now we have the prevout_n, the scriptPubKey, the type and the value of this transaction ID.
Now close Electrum.


We are almost finished, now open Bitcoin Gold Core wallet.
Create a wallet of course, click receive, generate an address in which we will receive our BTG, paste it in a new block note to not get confused.
....

From this point on, the guide shows how to create the raw transaction (sending to your desired BTG address), and then how to sign it using the redeem script and each of the private keys that you have... and then finally broadcasting it.

Granted, the tutorial isn't the best... but the general idea is correct.

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
October 24, 2019, 05:50:44 PM
 #11

- use the signrawtransaction command to sign it with your list of keys.
How do I do this part using QT for BCD without syncing the whole blockchain? I really dont trust the BCD nodes.

i have not tested this command but try using this:
Code:
signrawtransactionwithkey "rawtxhex" ["privatekey1","privatekey2"] ( [{"txid":"id","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}] )

replace "rawtxhex" with your raw transaction hex,
"privatekey1" and 2 are the keys to sign the transaction (if it didn't work try using 1 key at a time and do the whole thing twice but the second time use the result from previous step)
"id" is the txid you are spending
n is the index i explained above
pubScrHex is your P2SH script (your address converted to its script form)
redeemhex is your redeem script

ref: https://bitcoincore.org/en/doc/0.18.0/rpc/rawtransactions/signrawtransactionwithkey/

I followed exactly what is stated here. Everything appeared to be perfect till the last step where I tried to broadcast the RawTx in Hex format using sendrawtransaction through Console of Debug Window. I am receiving the following error...

non-final (code 64) (code -26)

What does this error signifies?

Please note that, my Core Wallet is not synced so far.

pooya87
Legendary
*
Online Online

Activity: 1890
Merit: 2266


Remember tonight for it's the beginning of forever


View Profile
October 24, 2019, 06:19:42 PM
 #12

non-final (code 64) (code -26)
What does this error signifies?
Please note that, my Core Wallet is not synced so far.

i have seen this error only when locktime is involved and it is not yet reached. check your transaction locktime and make sure it is set to a recent past block height. in this case i don't think not being synced changes anything since your node should still know the highest block height.

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
October 24, 2019, 06:37:42 PM
 #13

non-final (code 64) (code -26)
What does this error signifies?
Please note that, my Core Wallet is not synced so far.

i have seen this error only when locktime is involved and it is not yet reached. check your transaction locktime and make sure it is set to a recent past block height. in this case i don't think not being synced changes anything since your node should still know the highest block height.

But, I used the following command to generate RawTx in Hex format...

Code:
signrawtransactionwithkey "rawtxhex" ["privatekey1","privatekey2"] ( [{"txid":"id","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}] )

There is no mention of locktime in it. How did it kick in? Is there any way to specify it as a parameter in signrawtransactionwithkey, so that it does not create an issue in broadcast?

pooya87
Legendary
*
Online Online

Activity: 1890
Merit: 2266


Remember tonight for it's the beginning of forever


View Profile
October 25, 2019, 03:44:07 AM
 #14

But, I used the following command to generate RawTx in Hex format...

that command signs the rawtx that you already have (generates signature not the tx itself) and in your unsigned rawtx you must have already set a locktime.
in that hex string check the last 4 bytes (8 characters) that is the locktime. use decoderawtransaction to decode and see your locktime value.

i am not sure if BIP68 causes the same error (i had some trouble with it recently) but it may. the easiest way to get rid of it is to change your transaction version to 1 instead of 2.

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
October 25, 2019, 12:15:59 PM
 #15

But, I used the following command to generate RawTx in Hex format...

that command signs the rawtx that you already have (generates signature not the tx itself) and in your unsigned rawtx you must have already set a locktime.
in that hex string check the last 4 bytes (8 characters) that is the locktime. use decoderawtransaction to decode and see your locktime value.

i am not sure if BIP68 causes the same error (i had some trouble with it recently) but it may. the easiest way to get rid of it is to change your transaction version to 1 instead of 2.

Yes. RawTxHex was created with createrawtransaction, where the format is as follows...

Code:
createrawtransaction '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]' '{"BCDAddress":BalanceToTransfer}'

There is no mention of locktime in it either. I applied decoderawtransaction on RawTxHex. This yielded...

Code:
"version": 12,
"locktime": 0,

Is there anything wrong with this?

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
October 25, 2019, 06:45:07 PM
 #16

I have redone all the steps...

Step 1
Code:
createrawtransaction '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]' '{"BCDAddress":BalanceToTransfer}'

Output: RawTxHex

Step 2
Code:
signrawtransactionwithkey 'RawTxHex' '["privatekey1","privatekey2"]' '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]'

Output: {"hex": "SignedRawTxHex",  "complete": true}

Step 3
Code:
sendrawtransaction SignedRawTxHex

Output: Missing inputs (code -25)


Please note that, my Core Wallet is not synced so far.

CounterEntropy
Full Member
***
Offline Offline

Activity: 176
Merit: 181


View Profile
October 25, 2019, 11:26:32 PM
Merited by 100bitcoin (30), nc50lc (2), pooya87 (1)
 #17

I have redone all the steps...

Step 1
Code:
createrawtransaction '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]' '{"BCDAddress":BalanceToTransfer}'

Output: RawTxHex

Step 2
Code:
signrawtransactionwithkey 'RawTxHex' '["privatekey1","privatekey2"]' '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]'

Output: {"hex": "SignedRawTxHex",  "complete": true}
So far, you were heading towards the right direction.


Step 3
Code:
sendrawtransaction SignedRawTxHex

Output: Missing inputs (code -25)


Please note that, my Core Wallet is not synced so far.
Error Code -25 is RPC verify error. This is a general error during transaction or block submission.

Reference: https://github.com/bitcoin/bitcoin/blob/master/src/rpc/protocol.h#L46

'Missing inputs' means your wallet is unable to verify your inputs for the transaction you are trying to broadcast. This is happening because your Core Wallet is out of sync. If you wait and sync the wallet to the latest block, this would go through.


But, there is a hack to speed up this process.

1. Copy your SignedRawTxHex and exit Core Wallet.

2. Open the Electrum wallet, which you said in OP that you tried.

3. Go to Tools > Load transaction > From text.

4. Copy-paste your SignedRawTxHex and click on Load transaction.

5. Transaction window will show you details of your signed transaction. Verify everything and click on Broadcast.

You are done without syncing your Core Wallet. Now wait for your transaction to be included in a block and your coins have moved. Wink
nc50lc
Hero Member
*****
Online Online

Activity: 840
Merit: 905


Self-proclaimed Genius ㊙️


View Profile WWW
October 26, 2019, 04:15:37 AM
 #18

Good thing he came up with this.

If this is the site:
https://www.bitcoindiamond.org/download/
According to step2, he's talking about Electrum BCD which is Bitcoin Diamond fork of electrum.
If you're talking about the reference, BCD Core and Bitcoin Core share the same features (almost).

So it'll work.

100bitcoin
Sr. Member
****
Offline Offline

Activity: 688
Merit: 343


View Profile
November 16, 2019, 04:03:17 PM
Last edit: November 20, 2019, 11:10:38 PM by 100bitcoin
 #19

I have redone all the steps...

Step 1
Code:
createrawtransaction '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]' '{"BCDAddress":BalanceToTransfer}'

Output: RawTxHex

Step 2
Code:
signrawtransactionwithkey 'RawTxHex' '["privatekey1","privatekey2"]' '[{"txid":"TXID","vout":n,"scriptPubKey":"pubScrHex","redeemScript":"redeemhex"}]'

Output: {"hex": "SignedRawTxHex",  "complete": true}
So far, you were heading towards the right direction.


Step 3
Code:
sendrawtransaction SignedRawTxHex

Output: Missing inputs (code -25)


Please note that, my Core Wallet is not synced so far.
Error Code -25 is RPC verify error. This is a general error during transaction or block submission.

Reference: https://github.com/bitcoin/bitcoin/blob/master/src/rpc/protocol.h#L46

'Missing inputs' means your wallet is unable to verify your inputs for the transaction you are trying to broadcast. This is happening because your Core Wallet is out of sync. If you wait and sync the wallet to the latest block, this would go through.


But, there is a hack to speed up this process.

1. Copy your SignedRawTxHex and exit Core Wallet.

2. Open the Electrum wallet, which you said in OP that you tried.

3. Go to Tools > Load transaction > From text.

4. Copy-paste your SignedRawTxHex and click on Load transaction.

5. Transaction window will show you details of your signed transaction. Verify everything and click on Broadcast.

You are done without syncing your Core Wallet. Now wait for your transaction to be included in a block and your coins have moved. Wink

Fantastic!

This solves the problem I am trying to solve since July 26, 2019.

Thanks a LOT. Its a great relief to ultimately move the coins. I'll never use anything other than a legacy address ever again.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!