signrawtransaction returns "Invalid private key"

+1 vote

Hello!

I've been testing for a couple of days now, and I don't get to sign a raw transaction. These are the steps I follow:

1. createrawtransaction spending some amount of an asset from an unspent transaction

2. signrawtransaction "xxx" '[]' '["base58"]'

I get:

error code: -5
error message:
Invalid private key


I have read in bitcoin documentation that the private key must be a base58-encoded string, so I encoded the 64 hexadecimal digits key, but still the same error.

Can you help me with this error? Thank you.

asked Nov 8, 2016 by David

1 Answer

0 votes
You need to base58-encode the raw binary private key, not its hexadecimal representation. You should expect it to be around 52 characters long.
answered Nov 10, 2016 by MultiChain
Thank you, I was using the hex form. However, still the same error.
When encoding in base58 I get 44 chars. Could you please check for me if these keys sound OK to you?
I have my private key (32 bytes = 64 hex characters): 684487e7e157e3add611056f3c5112883638137e8b5a7af602352abe464adcde
This is the base58 encoded version (44 characters): 8221ZPGDoVprjtD7MN6Mduibt8Z7saBTK5YAs9hWCEeZ
 
I have even tried to call signrawtransactions with the private key in your documentation (http://www.multichain.com/developers/address-format/) and I get the same error:

Private key: 18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725
Log from my code showing that I have the right hex representation: <Buffer 18 e1 4a 7b 6a 30 7f 42 6a 94 f8 11 47 01 e7 c8 e7 74 e7 f9 a4 7e 2c 20 35 db 29 a2 06 32 17 25>
Base58 encoded form (44 bytes): 2g82vgrZTviKG5sN1g2VM7FHgHTm16ej4gmr8ECMzab6

My call:
signrawtransaction '01000000026d191ac893f1faec628ab946061b7b85421c6bac94fd57a335eac994ab6e5a980000000000ffffffff17438459d932c874567b1b840f4282b2b730218cbe87c589a863f830fd643f3c0000000000ffffffff0100000000000000003176a914ce9e4d0539328cb5dcc1b9f23ce7818581e09c8488ac1673706b710500000008010000190058020000000000007500000000' '[]' '["2g82vgrZTviKG5sN1g2VM7FHgHTm16ej4gmr8ECMzab6"]'
{"method":"signrawtransaction","params":["01000000026d191ac893f1faec628ab946061b7b85421c6bac94fd57a335eac994ab6e5a980000000000ffffffff17438459d932c874567b1b840f4282b2b730218cbe87c589a863f830fd643f3c0000000000ffffffff0100000000000000003176a914ce9e4d0539328cb5dcc1b9f23ce7818581e09c8488ac1673706b710500000008010000190058020000000000007500000000",[],["2g82vgrZTviKG5sN1g2VM7FHgHTm16ej4gmr8ECMzab6"]],"id":1,"chain_name":"tests"}

error code: -5
error message:
Invalid private key

Could you please help me in showing me what I'm doing wrong?
Doing more search, I have found this question ( http://www.multichain.com/qa/842/private-key-format ) in which wmiki describes a method similar to the creation of addresses (double hash, XOR...). I have tried many variations aroud what wmiki partially describes but I always get the "Invalid private key".

Could you give an unambiguous answer about how to calculate the private key that signrawtransaction expects? Please, don't forward me to Multichain address format or other documentation about Bitcoin. I've been digging in dozens of pages for days, but I haven't got to avoid this error.
First of all, if your keys are stored inside MultiChain wallet, the easiest way to get private key (already properly encoded) is to use dumpprivkey API.

If you prefer to store private key externally, then the procedure is similar to that described at http://www.multichain.com/developers/address-format/, but slightly different. Here is an example:

1. Take private key - 32 bytes:
b69ca8ffae36f11ad445625e35bf6ac57d6642ddbe470dd3e7934291b2000d78

2. Important! Probably this is what you need! If the public key is compressed - add 0x01 in the end:

b69ca8ffae36f11ad445625e35bf6ac57d6642ddbe470dd3e7934291b2000d7801

3. Take private-key-version from params.dat:
8025b89e

4. Insert private-key-version bytes uniformly into result of 2, i.e. after every 8(!) bytes:

80b69ca8ffae36f11a25d445625e35bf6ac5b87d6642ddbe470dd39ee7934291b2000d7801

5. 6-10 from the link above (hashes, checksums and XORs)

80b69ca8ffae36f11a25d445625e35bf6ac5b87d6642ddbe470dd39ee7934291b2000d780134c1787e

6. base-58 encoding:

VEEWgYhDhqWnNnDCXXjirJYXGDFPjH1B8v6hmcnj1kLXrkpxArmz7xXw

Please let us know if it doesn't work.
Thank you so much! It finally works!
Just as a recommendation to improve your site, it would be great if you create a step-by-step page with this procedure, in the same way you already did it with the Address format.

Thank you again (I've been trying to solve this for 2 weeks now).
Thanks, good idea - we'll add this to the address format page.
...