Title: Sign transaction across wallet Post by: madmadmax on May 26, 2013, 05:19:53 AM Say I use the standard bitcoin-qt, how can I sign a transaction with public keys from the currently loaded wallet and other specific inputs from private keys without importing them?
Title: Re: Sign transaction across wallet Post by: scintill on May 26, 2013, 06:03:19 AM Assuming you're already dealing with a raw transaction, the signrawtransaction command (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) lets you specify additional private keys as an optional last parameter. I think for keys already in your wallet (and referenced by the raw transaction), it will find them automatically.
createrawtransaction takes arbitrary outputs and address:amount pairs and creates a hex transaction string. listunspent will show you the unspent outputs for keys that are in your wallet. Title: Re: Sign transaction across wallet Post by: madmadmax on May 26, 2013, 11:22:29 AM Assuming you're already dealing with a raw transaction, the signrawtransaction command (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) lets you specify additional private keys as an optional last parameter. I think for keys already in your wallet (and referenced by the raw transaction), it will find them automatically. createrawtransaction takes arbitrary outputs and address:amount pairs and creates a hex transaction string. listunspent will show you the unspent outputs for keys that are in your wallet. The problem is I don't want to use all of the input under that private key, just half here and half under the private key. Title: Re: Sign transaction across wallet Post by: DannyHamilton on May 26, 2013, 01:53:43 PM Assuming you're already dealing with a raw transaction, the signrawtransaction command (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) lets you specify additional private keys as an optional last parameter. I think for keys already in your wallet (and referenced by the raw transaction), it will find them automatically. createrawtransaction takes arbitrary outputs and address:amount pairs and creates a hex transaction string. listunspent will show you the unspent outputs for keys that are in your wallet. The problem is I don't want to use all of the input under that private key, just half here and half under the private key. I'm not sure if you are saying that there are multiple outputs associated with the private key, and you don't want to use all of them as inputs to your transaction. . . Or if you are saying there is only one output associated with the private key, and you don't want to use all of that output as an input. If there are multiple outputs, then createrawtransaction allows you to specify which of those outputs you want to use as inputs, so you don't have to use all of them if you don't want to. If there is only one output, then you have to use the entire output. That's how bitcoin works. It is not possible to only use a portion of an output. The output is spent completely as an input, and then you have to create a new output that sends any excess back to your wallet. If you forget to create the output that sends the "change" from the transaction back to your wallet, then the miner will get all of it as a transaction fee. Title: Re: Sign transaction across wallet Post by: scintill on May 27, 2013, 12:28:41 AM The problem is I don't want to use all of the input under that private key, just half here and half under the private key. As DannyHamilton said, you pick whatever outputs you want. listunspent just shows you your options. Remember you have to spend an output's entire balance at once, though. To clarify on automatically finding keys, you give createrawtransaction the outputs you want to spend, which embeds them into the hex string it returns. signrawtransaction looks at those outputs, figures out the associated key, and signs them if it has the associated private key in its wallet or specified on the command line. None of these steps will automatically add outputs/inputs, they only do what you tell them to. Title: Re: Sign transaction across wallet Post by: madmadmax on May 27, 2013, 04:35:05 AM Assuming you're already dealing with a raw transaction, the signrawtransaction command (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) lets you specify additional private keys as an optional last parameter. I think for keys already in your wallet (and referenced by the raw transaction), it will find them automatically. createrawtransaction takes arbitrary outputs and address:amount pairs and creates a hex transaction string. listunspent will show you the unspent outputs for keys that are in your wallet. The problem is I don't want to use all of the input under that private key, just half here and half under the private key. I'm not sure if you are saying that there are multiple outputs associated with the private key, and you don't want to use all of them as inputs to your transaction. . . Or if you are saying there is only one output associated with the private key, and you don't want to use all of that output as an input. If there are multiple outputs, then createrawtransaction allows you to specify which of those outputs you want to use as inputs, so you don't have to use all of them if you don't want to. If there is only one output, then you have to use the entire output. That's how bitcoin works. It is not possible to only use a portion of an output. The output is spent completely as an input, and then you have to create a new output that sends any excess back to your wallet. If you forget to create the output that sends the "change" from the transaction back to your wallet, then the miner will get all of it as a transaction fee. The problem is I don't want to use all of the input under that private key, just half here and half under the private key. As DannyHamilton said, you pick whatever outputs you want. listunspent just shows you your options. Remember you have to spend an output's entire balance at once, though. To clarify on automatically finding keys, you give createrawtransaction the outputs you want to spend, which embeds them into the hex string it returns. signrawtransaction looks at those outputs, figures out the associated key, and signs them if it has the associated private key in its wallet or specified on the command line. None of these steps will automatically add outputs/inputs, they only do what you tell them to. Yes I understand that, what I'm asking is whenever I can create a raw transaction with inputs from the current listunspent and add another input which isn't on listunspent but from a different wallet and then just specify the private key on createrawtransaction? Title: Re: Sign transaction across wallet Post by: scintill on May 27, 2013, 06:14:17 AM Yes I understand that, what I'm asking is whenever I can create a raw transaction with inputs from the current listunspent and add another input which isn't on listunspent but from a different wallet and then just specify the private key on createrawtransaction? Actually, I just noticed this in the help message for signrawtransaction: Quote Third optional argument (may be null) is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction. So, if you don't specify that parameter, it will find keys in your wallet, but can only use the ones that are in it. If you do give it, it won't look in your wallet. My tests seem to confirm this. A way around this that seemed to work for me for a test with 2 keys (one in wallet, one not), was to signrawtransaction with no keys, which gave a partially-signed transaction from the wallet key. Then I copied the output into another signrawtransaction and passed the remaining private key as a parameter. The result had "complete":true and the decoded transaction appeared to have both signatures, so I think that would work. I'm not sure if there's a nicer way to do this. Maybe someone with more experience with the RPC API knows. The raw transactions wiki page (https://en.bitcoin.it/wiki/Raw_Transactions) may also be helpful. Title: Re: Sign transaction across wallet Post by: madmadmax on May 28, 2013, 04:36:14 AM Yes I understand that, what I'm asking is whenever I can create a raw transaction with inputs from the current listunspent and add another input which isn't on listunspent but from a different wallet and then just specify the private key on createrawtransaction? Actually, I just noticed this in the help message for signrawtransaction: Quote Third optional argument (may be null) is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction. So, if you don't specify that parameter, it will find keys in your wallet, but can only use the ones that are in it. If you do give it, it won't look in your wallet. My tests seem to confirm this. A way around this that seemed to work for me for a test with 2 keys (one in wallet, one not), was to signrawtransaction with no keys, which gave a partially-signed transaction from the wallet key. Then I copied the output into another signrawtransaction and passed the remaining private key as a parameter. The result had "complete":true and the decoded transaction appeared to have both signatures, so I think that would work. I'm not sure if there's a nicer way to do this. Maybe someone with more experience with the RPC API knows. The raw transactions wiki page (https://en.bitcoin.it/wiki/Raw_Transactions) may also be helpful. Thanks!! What did you pass as the second argument? Title: Re: Sign transaction across wallet Post by: scintill on May 29, 2013, 02:38:30 AM Thanks!! What did you pass as the second argument? Null. So Code: signrawtransaction <hex string> null '["5Ksdfsd..."]' Title: Re: Sign transaction across wallet Post by: kodo on May 29, 2013, 04:54:54 AM hmm im not sure about this.
Title: Re: Sign transaction across wallet Post by: madmadmax on May 29, 2013, 06:05:52 PM Thanks!! What did you pass as the second argument? Null. So Code: signrawtransaction <hex string> null '["5Ksdfsd..."]' Thanks!!!! :D Title: Re: Sign transaction across wallet Post by: kodo on May 29, 2013, 06:21:04 PM Glad you got this worked out.
Title: Re: Sign transaction across wallet Post by: madmadmax on May 30, 2013, 12:50:42 PM Glad you got this worked out. I get "Expected type array, got str" for some reason, this is what I send: {"jsonrpc":"1.0","id":"1","method":"signrawtransaction","params":["myhex","null",["myprivatekey"]]} where have I went wrong? Title: Re: Sign transaction across wallet Post by: kjj on May 30, 2013, 01:15:04 PM Erm, I'm pretty sure you need to pass in an empty array there, and not the string "null".
Title: Re: Sign transaction across wallet Post by: madmadmax on May 30, 2013, 02:43:33 PM Erm, I'm pretty sure you need to pass in an empty array there, and not the string "null". Nope, if I pass it empty I still get the same error. Title: Re: Sign transaction across wallet Post by: kjj on May 30, 2013, 04:31:11 PM Are you passing an empty array, or an empty string?
'[]' Title: Re: Sign transaction across wallet Post by: scintill on May 30, 2013, 06:04:43 PM My use of null was at the Debug Console in bitcoin-qt, so maybe it's different for JSON-RPC. I don't know the RPC format, but assuming you're basically right, I would try:
{"jsonrpc":"1.0","id":"1","method":"signrawtransaction","params":["myhex",[],["myprivatekey"]]} {"jsonrpc":"1.0","id":"1","method":"signrawtransaction","params":["myhex",null,["myprivatekey"]]} |