Author

Topic: multi-sign and Invalid private key (code -5) (Read 855 times)

hero member
Activity: 560
Merit: 509
I prefer Zakir over Muhammed when mentioning me!
-snip-

Quote
You are using the wrong private key. Since this is a testnet transaction, you must sign it using a private key in testnet format. The private key that you posted above is for the mainnet. Testnet private keys start with either '9' or 'c'.

I'he used next site for generation keys == https://brainwallet.org/#generator
which site for the test net do you recommend ?

 -snip-

You need to choose 'Testnet' from the list you get when you click 'BTC'(top right) to get testnet address and its corresponding private key. Anyway, why don't you use Bitcoin Core to create testnet address?

 - https://bitcoin.org/en/developer-examples#testnet
 - https://bitcoin.org/en/developer-examples#p2sh-multisig
jr. member
Activity: 43
Merit: 7
Thanks.

Quote
You are using the wrong private key. Since this is a testnet transaction, you must sign it using a private key in testnet format. The private key that you posted above is for the mainnet. Testnet private keys start with either '9' or 'c'.

I'he used next site for generation keys == https://brainwallet.org/#generator
which site for the test net do you recommend ?

Quote
Also, I don't think you included the scriptpubkey or the redeemscript in the createrawtransaction. Be sure to do that. Follow Gavin's instructions in the link.

According to the example
Code:
signrawtransaction '0100000001cdba95b55...' 
'[
{"txid":"30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd",
"vout":1,"scriptPubKey":"76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac",
"redeemScript":"5241045"}]'
'["5K9T8VGcAztUQs5rSRGnf6oEwymY4k8YJV7MBfU5T3LD4H3wK2E"]'

BR!
staff
Activity: 3458
Merit: 6793
Just writing some code
Code:
signrawtransaction '0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300100000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000' 

'[{"txid":"30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd","vout":1,"scriptPubKey":"76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac",
"redeemScript":"5241045e8385118c8b77a044390364dd5fb8c4864d138491fc788948be81f6842f45bc6b6c9401a90f8479b2af8191b7a6a7735053f2724668cf8af8a2c30d853b801141042cb46c5cfa2a5af18effd8296e7aeda287d407ccc2e42cc15bb7d27c6f84e4a78ade99d1aa7e8efa2fd63f8573548ec1a33f53e0135ccbe15bc5c9eb0d6e0cfd4104d109b4e95fd48162e5424fe71d769c9cb4bc8cb40224ab6b8d1e9fac6f6925c34c902d38caebebf2703a7685bf788adfee83bffa637f95d3c782c3d4bb0120f553ae"}]'

'["5K9T8VGcAztUQs5rSRGnf6oEwymY4k8YJV7MBfU5T3LD4H3wK2E"]'


Invalid private key (code -5)

what is wrong ?

Also tried to use this example 2 of 3 https://gist.github.com/gavinandresen/3966071
The error message same 
10:42:00

Invalid private key (code -5)

What should I change ?

BR!
You are using the wrong private key. Since this is a testnet transaction, you must sign it using a private key in testnet format. The private key that you posted above is for the mainnet. Testnet private keys start with either '9' or 'c'. BTW, you should never post your private keys online.

Also, I don't think you included the scriptpubkey or the redeemscript in the createrawtransaction. Be sure to do that. Follow Gavin's instructions in the link.
jr. member
Activity: 43
Merit: 7
Hello!

Thank you for your answer.

I have tried to change vout from 0 to 1

Code:
createrawtransaction '''
[
{
"txid": "'30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd'",
"vout": '1'
}
]
''' '''
{
"motbFuaf7Q7xWqBbo7zFu83sdNBspvYkFY": 1.9999
}'''

0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300100000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000

and decode it

Code:
decoderawtransaction 
0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300100000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000

{
"txid" : "3c97e250e8a67d1adacc86f56a2b29a32e4f7835586d681d0bc788b73587c622",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd",
"vout" : 1,
"scriptSig" : {
"asm" : "",
"hex" : ""
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 1.99990000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 5bd898bbe4a000cda4418c1fd28178ec99cd653e OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"motbFuaf7Q7xWqBbo7zFu83sdNBspvYkFY"
]
}
}
]
}

As you can  see vout == 1

but the error message same

Code:
signrawtransaction '0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300100000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000' 

'[{"txid":"30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd","vout":1,"scriptPubKey":"76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac",
"redeemScript":"5241045e8385118c8b77a044390364dd5fb8c4864d138491fc788948be81f6842f45bc6b6c9401a90f8479b2af8191b7a6a7735053f2724668cf8af8a2c30d853b801141042cb46c5cfa2a5af18effd8296e7aeda287d407ccc2e42cc15bb7d27c6f84e4a78ade99d1aa7e8efa2fd63f8573548ec1a33f53e0135ccbe15bc5c9eb0d6e0cfd4104d109b4e95fd48162e5424fe71d769c9cb4bc8cb40224ab6b8d1e9fac6f6925c34c902d38caebebf2703a7685bf788adfee83bffa637f95d3c782c3d4bb0120f553ae"}]'

'["5K9T8VGcAztUQs5rSRGnf6oEwymY4k8YJV7MBfU5T3LD4H3wK2E"]'


Invalid private key (code -5)

what is wrong ?

Also tried to use this example 2 of 3 https://gist.github.com/gavinandresen/3966071
The error message same 
10:42:00

Invalid private key (code -5)

What should I change ?

BR!
staff
Activity: 3458
Merit: 6793
Just writing some code
3) Checked address and txid
Code:
https://www.blocktrail.com/tBTC/address/2MvDgSTXGEbi9nm4UhP1B6Wvi7LMJ9MAdmu/transactions
30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd
If you look up this transaction in the blockexplorer, you will see that there are 2 outputs from this transaction.
The first one is to mwNenFE8gFfjz2p2osbsYXAcPt6gnGGKSk and the second to 2MvDgSTXGEbi9nm4UhP1B6Wvi7LMJ9MAdmu.
The second one is to your address. These outputs go in an array, with the first having an index of 0, second has an index of 1, and so on. Now lets look at your raw transactions.

4) Created rawTX
Code:
createrawtransaction '''
[
{
"txid": "'30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd'",
"vout": '0'
}
]
''' '''
{
"motbFuaf7Q7xWqBbo7zFu83sdNBspvYkFY": 1.9999
}'''

0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300000000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000
In your vins, you specify the txid and the index of the output you wish to spend. In this case, the index of the output is 1, not 0 because the output is the second in the array. Therefore, instead of
Code:
"vout": '0'
you should have
Code:
"vout": '1'

Your error is coming from not having the private key to spend the first output.
jr. member
Activity: 43
Merit: 7
Hello,

I am truing to spend coins from P2SH address.

step by step


1) Generated keys
Code:
# https://brainwallet.org/#generator

#SEED 1 => nativeapi seed generatoin one
#privateKey => 5K9T8VGcAztUQs5rSRGnf6oEwymY4k8YJV7MBfU5T3LD4H3wK2E
#publicKey => 045e8385118c8b77a044390364dd5fb8c4864d138491fc788948be81f6842f45bc6b6c9401a90f8479b2af8191b7a6a7735053f2724668cf8af8a2c30d853b8011
#
#SEED 2 => nativeapi seed generatoin two
#privateKey => 5JFoZ6gW7dkwbtZVSyvxneRead1AzaiGvxyVpEa3n6k34321AXA
#publicKey => 042cb46c5cfa2a5af18effd8296e7aeda287d407ccc2e42cc15bb7d27c6f84e4a78ade99d1aa7e8efa2fd63f8573548ec1a33f53e0135ccbe15bc5c9eb0d6e0cfd
#
#SEED 3 => nativeapi seed generatoin three
#privateKey => 5JRrkriuY9s64h4eUBzqSrtZL1UFKgAvrhJPAUaVadrHSBxS75y
#publicKey => 04d109b4e95fd48162e5424fe71d769c9cb4bc8cb40224ab6b8d1e9fac6f6925c34c902d38caebebf2703a7685bf788adfee83bffa637f95d3c782c3d4bb0120f5


2) combine the three keys into a multisig address:
Code:
./bitcoind createmultisig 2 '["045e8385118c8b77a044390364dd5fb8c4864d138491fc788948be81f6842f45bc6b6c9401a90f8479b2af8191b7a6a7735053f2724668cf8af8a2c30d853b8011","042cb46c5cfa2a5af18effd8296e7aeda287d407ccc2e42cc15bb7d27c6f84e4a78ade99d1aa7e8efa2fd63f8573548ec1a33f53e0135ccbe15bc5c9eb0d6e0cfd","04d109b4e95fd48162e5424fe71d769c9cb4bc8cb40224ab6b8d1e9fac6f6925c34c902d38caebebf2703a7685bf788adfee83bffa637f95d3c782c3d4bb0120f5"]'

3) Checked address and txid
Code:
https://www.blocktrail.com/tBTC/address/2MvDgSTXGEbi9nm4UhP1B6Wvi7LMJ9MAdmu/transactions
30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd

4) Created rawTX
Code:
createrawtransaction '''
[
{
"txid": "'30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd'",
"vout": '0'
}
]
''' '''
{
"motbFuaf7Q7xWqBbo7zFu83sdNBspvYkFY": 1.9999
}'''

0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300000000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000


5) Decoded raw tx and get - scriptPubKey hex
Code:
decoderawtransaction 0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300000000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000

{
"txid" : "530aa989a79a2738d2b6b956b6fdc788818fcd334963036aa6d6686598b6d492",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd",
"vout" : 0,
"scriptSig" : {
"asm" : "",
"hex" : ""
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 1.99990000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 5bd898bbe4a000cda4418c1fd28178ec99cd653e OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"motbFuaf7Q7xWqBbo7zFu83sdNBspvYkFY"
]
}
}
]
}


6) Tried to sign it by the first key

Code:
signrawtransaction '0100000001cdba95b552d24a50182208816179578544d6d623fb0ca1dfbec4e6c845e6a9300000000000ffffffff01f09aeb0b000000001976a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac00000000' 

'[{"txid":"30a9e645c8e6c4bedfa10cfb23d6d6448557796181082218504ad252b595bacd","vout":0,

"scriptPubKey":"76a9145bd898bbe4a000cda4418c1fd28178ec99cd653e88ac","redeemScript":"5241045e8385118c8b77a044390364dd5fb8c4864d138491fc788948be81f6842f45bc6b6c9401a90f8479b2af8191b7a6a7735053f2724668cf8af8a2c30d853b801141042cb46c5cfa2a5af18effd8296e7aeda287d407ccc2e42cc15bb7d27c6f84e4a78ade99d1aa7e8efa2fd63f8573548ec1a33f53e0135ccbe15bc5c9eb0d6e0cfd4104d109b4e95fd48162e5424fe71d769c9cb4bc8cb40224ab6b8d1e9fac6f6925c34c902d38caebebf2703a7685bf788adfee83bffa637f95d3c782c3d4bb0120f553ae"}]'

'["5K9T8VGcAztUQs5rSRGnf6oEwymY4k8YJV7MBfU5T3LD4H3wK2E"]'

Have got -> Invalid private key (code -5)


What have I done wrong? some incorrect parameters or steps ?

Regards.
Jump to: