Author

Topic: How to sign an Unsigned RawTx from 2-of-3 Multi-Sig Address using Bitcoin Core? (Read 401 times)

sr. member
Activity: 856
Merit: 422
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.
legendary
Activity: 2338
Merit: 5297
Self-proclaimed Genius
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.
full member
Activity: 214
Merit: 275
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
sr. member
Activity: 856
Merit: 422
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.
sr. member
Activity: 856
Merit: 422
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?
legendary
Activity: 3402
Merit: 10424
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.
sr. member
Activity: 856
Merit: 422
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?
legendary
Activity: 3402
Merit: 10424
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.
sr. member
Activity: 856
Merit: 422
- 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.
HCP
legendary
Activity: 2086
Merit: 4314
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://talkimg.com/images/2023/11/15/z72Qo.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.
sr. member
Activity: 856
Merit: 422
- 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://bitcointalksearch.org/topic/tutorial-how-to-extract-bitcoin-gold-from-a-2fa-electrum-wallet-step-by-step-2550529

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
Activity: 2086
Merit: 4314
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://bitcointalksearch.org/topic/tutorial-how-to-extract-bitcoin-gold-from-a-2fa-electrum-wallet-step-by-step-2550529

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.
jr. member
Activity: 67
Merit: 3
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.
legendary
Activity: 3402
Merit: 10424
- 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/
sr. member
Activity: 856
Merit: 422
- 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.
legendary
Activity: 3402
Merit: 10424
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
legendary
Activity: 2338
Merit: 5297
Self-proclaimed Genius
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.
legendary
Activity: 3416
Merit: 1912
The Concierge of Crypto
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.
sr. member
Activity: 856
Merit: 422
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://bitcointalksearch.org/topic/how-to-import-2-of-3-multi-sig-keys-to-electrum-wallet-5169272). 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?
Jump to: