Title: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 05:43:57 PM I want to spend 0.01 tBTC from vout 0 of txid 5fbce786b0bd9f46e0511a5e8091d57900e2eb5d4132375aada3e964a75e6ca5
on testnet from: n2eTmd37KTGhRZNJsf9tfVdCG1YejciETu (0.01 tBTC) to: 0.005 tBTC -> 2NCo1Y7JJgLabJ5AQjBpgavyX1JLWJxGPYK change: 0.004 tBTC -> n2eTmd37KTGhRZNJsf9tfVdCG1YejciETu fees: 0.001 tBTC Code: createrawtransaction '[{"txid":"5fbce786b0bd9f46e0511a5e8091d57900e2eb5d4132375aada3e964a75e6ca5","vout":0}]' output: 0100000001a56c5ea764e9a3ad5a3732415debe20079d591805e1a51e0469fbdb086e7bc5f0000 000000ffffffff0220a107000000000017a914d66d4e8e58f8e1457fd3c3dff2def8f7075fa778 87801a0600000000001976a914e7c6286efb8730ef8211964f5046e0a0e3568bf788ac00000000 the problem is when I try to sign that tx: Code: signrawtransaction "0100000001a56c5e...211964f5046e0a0e3568bf788ac00000000" output: Invalid private key (code -5) I also tried with WIF format: 14xCi3eQ3AJvk...xyEQRooQNv1GGQSb with the same output... what's wrong ? If I don't use the wallet of bitcoind, should I provide the "scriptPubKey" and the redeemScript ? If yes, it's easy to find the scriptPubKey in the previous tx but how do I create the redeemScript ? to verify that my private Key is valid, I tested it with bitcore (node.js): Code: bitcore = require('bitcore'); Title: Re: createrawtransaction: Invalid private key Post by: achow101 on November 19, 2015, 05:50:30 PM Your command for signrawtransaction is wrong. The developer docs and this page https://en.bitcoin.it/wiki/Raw_Transactions#signrawtransaction_.3Chex_string.3E_.5B.7B.22txid.22:txid.2C.22vout.22:n.2C.22scriptPubKey.22:hex.7D.2C....5D_.5B.3Cprivatekey1.3E.2C....5D_.5Bsighash.3D.22ALL.22.5DD should help.
Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 07:37:11 PM From the developer doc:
Quote signrawtransaction <hex string> [{"txid":txid,"vout":n,"scriptPubKey":hex},...] [<privatekey1>,...] [sighash="ALL"] 1) Sign as many inputs as possible for raw transaction (serialized, hex-encoded). Quote The first argument may be several variations of the same transaction concatenated together; I want to spend only 1 output which needs only 1 signature (P2PK):signatures from all of them will be combined together, along with signatures for keys in the local wallet. My first argument is the result of: Code: createrawtransaction '[{"txid":"5fbce786b0bd9f46e0511a5e8091d57900e2eb5d4132375aada3e964a75e6ca5","vout":0}]' --> "0100000001a56c5ea764e9a3ad5a3732415debe20079d591805e1a51e0469fbdb086e7bc5f00000 00000ffffffff0260e316000000000017a91 4d66d4e8e58f8e1457fd3c3dff2def8f7075fa77887801a0600000000001976a914e7c6286efb87 30ef8211964f5046e0a0e3568bf788ac00000000" 2) Quote The optional second argument is an array of parent transaction outputs, This argument is optionnal: I only have 1 tx with 1 input, not a chainso you can create a chain of raw transactions that depend on each other before sending them to the network (the parent tx is confirmed, I don't have a chain of tx to include in the same block) the second argument is empty: --> '[]' Just to make sure: I tried with the previous tx output with no difference: '[{"txid":"5fbce786b0bd9f46e0511a5e8091d57900e2eb5d4132375aada3e964a75e6ca5","vout":"0","scriptPubKey":"76a914e7c6286efb8730ef8211964f5046e0a0e3568bf788ac"}]' 3) Quote Third optional argument is an array of base58-encoded private keys that, the previous output is a simple array of one private Key (P2PK) corresponding to n2eTmd37KTGhRZNJsf9tfVdCG1YejciETuif given, will be the only keys used to sign the transaction. since I don't use the bitcoind wallet, I MUST give this private Key (it's not in the wallet) this private key should be in base-58 --> '["14xCi3eQ3AJvk...xyEQRooQNv1GGQSb"]' 4) Quote The fourth optional argument is a string that specifies how the signature hash I'm not sure about this one, If i try anything ("ALL", "NONE", "SINGLE"),is computed, and can be "ALL", "NONE", "SINGLE", "ALL|ANYONECANPAY", "NONE|ANYONECANPAY", or "SINGLE|ANYONECANPAY". I still have the "Invalid private key" error The default value is sighash="ALL" so this last argument is empty The final command is the same as in my first post but with the base-58 private key: 14xCi3eQ3AJvk...xyEQRooQNv1GGQSb with the same error: "Invalid private key (code -5)" Code: signrawtransaction "0100000001a56c5ea764e9a3ad5a3732415debe20079d591805e1a51e0469fbdb086e7bc5f0000000000ffffffff0260e316000000000017a914d66d4e8e58f8e1457fd3c3dff2def8f7075fa77887801a0600000000001976a914e7c6286efb8730ef8211964f5046e0a0e3568bf788ac00000000" Title: Re: createrawtransaction: Invalid private key Post by: achow101 on November 19, 2015, 07:45:52 PM Your private key is incorrect. It should be start with a '9' or a 'c' and be 51-52 characters long. Where did you get the private keys?
Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 07:56:12 PM Quote Where did you get the private keys? It has been generated by bitcore (node.js), for testnet.Code: var privateKey = new bitcore.PrivateKey(); the WIF format is 14xCi3eQ3AJvk...xyEQRooQNv1GGQSb and has 52 char Title: Re: createrawtransaction: Invalid private key Post by: achow101 on November 19, 2015, 08:11:07 PM Quote Where did you get the private keys? It has been generated by bitcore (node.js), for testnet.Code: var privateKey = new bitcore.PrivateKey(); the WIF format is 14xCi3eQ3AJvk...xyEQRooQNv1GGQSb and has 52 char Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 08:38:52 PM OK but here is a simple example:
Code: bitcore = require('bitcore'); Code: privateKey: 13421db757900dae2ecd471b2cca0d950f8ca47fd867e3c44dadd64f57194252 Title: Re: createrawtransaction: Invalid private key Post by: achow101 on November 19, 2015, 08:48:45 PM OK but here is a simple example: Something is definitely wrong with your install of Bitcore. It is not producing the proper WIF key. Again, it should start with a 'c' or '9'. In most cases, it should be a 'c'Code: bitcore = require('bitcore'); Code: privateKey: 13421db757900dae2ecd471b2cca0d950f8ca47fd867e3c44dadd64f57194252 Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 09:20:45 PM I made 2 tests with bitaddress.org (livenet)
<privkey> WIF = 5JoVxXdyoVFPaVL4xHQUvdb8vVRDFCdeh8A16fodXMiYKmrgtCu <pubkey> = 1KLgFamwn7cm1qQSnuFVuYw99dmWUVZC9b <privkey> WIF = 5K1xnQXX5d1xVaRab75HbLT6oPejddN1eUdesL8epMdjRgHVuqG <pubkey> = 1Npcxoh99nGGf829uJhvMWan4vUbTzfi9y If I understand well, the private key is the same in livenet and tesnet: the private key is just a ramdom number and the WIF format will also be the same. Then we calculate the <pubkey> by adding points on a elliptic curve, so the pubkey is a pair of coordinates (x,y). Then we write the pubkey like "04 x y" OR "02 x" (if y is positive) OR "03 x" (if y is negative). It is only when we create the base-58 pubkey that we use a different format so the pubkeys looks different in testnet and livenet. Is it correct ? Title: Re: createrawtransaction: Invalid private key Post by: achow101 on November 19, 2015, 09:25:56 PM If I understand well, the private key is the same in livenet and tesnet: No. The WIF format will be different to indicate which network that private key is meant for. For testnet it will start with 'c' or '9'. On the mainnet it will start with '5', 'K' or 'L'the private key is just a ramdom number and the WIF format will also be the same. Then we calculate the <pubkey> by adding points on a elliptic curve, Yes. Only after doing base58CheckEncoding to create the WIF format will the private key (encoded as WIF) and public key (encoded as an address) appear different.so the pubkey is a pair of coordinates (x,y). Then we write the pubkey like "04 x y" OR "02 x" (if y is positive) OR "03 x" (if y is negative). It is only when we create the base-58 pubkey that we use a different format so the pubkeys looks different in testnet and livenet. Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 19, 2015, 09:31:56 PM OK, Thanks a lot
I have to figure what's wrong with my bitcore module... Title: Re: createrawtransaction: Invalid private key Post by: redPanda on November 23, 2015, 07:09:38 PM UPDATE:
instead of: Code: bitcore.Networks.defaultNetwork = 'testnet'; WRONG Code: bitcore.Networks.defaultNetwork = bitcore.Networks.testnet; |