Author

Topic: Sign transaction across wallet (Read 1231 times)

sr. member
Activity: 448
Merit: 252
May 30, 2013, 02:04:43 PM
#17
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"]]}
kjj
legendary
Activity: 1302
Merit: 1025
May 30, 2013, 12:31:11 PM
#16
Are you passing an empty array, or an empty string?

'[]'
hero member
Activity: 740
Merit: 501
May 30, 2013, 10:43:33 AM
#15
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.
kjj
legendary
Activity: 1302
Merit: 1025
May 30, 2013, 09:15:04 AM
#14
Erm, I'm pretty sure you need to pass in an empty array there, and not the string "null".
hero member
Activity: 740
Merit: 501
May 30, 2013, 08:50:42 AM
#13
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?
newbie
Activity: 42
Merit: 0
May 29, 2013, 02:21:04 PM
#12
Glad you got this worked out.
hero member
Activity: 740
Merit: 501
May 29, 2013, 02:05:52 PM
#11
Thanks!!

What did you pass as the second argument?

Null.  So
Code:
signrawtransaction  null '["5Ksdfsd..."]'
  For the key-in-wallet part you can just give the hex string and it will default to null for the 2nd parameter.

Thanks!!!!  Cheesy
newbie
Activity: 42
Merit: 0
May 29, 2013, 12:54:54 AM
#10
hmm im not sure about this.
sr. member
Activity: 448
Merit: 252
May 28, 2013, 10:38:30 PM
#9
Thanks!!

What did you pass as the second argument?

Null.  So
Code:
signrawtransaction  null '["5Ksdfsd..."]'
  For the key-in-wallet part you can just give the hex string and it will default to null for the 2nd parameter.
hero member
Activity: 740
Merit: 501
May 28, 2013, 12:36:14 AM
#8
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 may also be helpful.

Thanks!!

What did you pass as the second argument?
sr. member
Activity: 448
Merit: 252
May 27, 2013, 02:14:17 AM
#7
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 may also be helpful.
hero member
Activity: 740
Merit: 501
May 27, 2013, 12:35:05 AM
#6
Assuming you're already dealing with a raw transaction, the signrawtransaction command 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?
sr. member
Activity: 448
Merit: 252
May 26, 2013, 08:28:41 PM
#5
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.
legendary
Activity: 3416
Merit: 4658
May 26, 2013, 09:53:43 AM
#4
Assuming you're already dealing with a raw transaction, the signrawtransaction command 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.
hero member
Activity: 740
Merit: 501
May 26, 2013, 07:22:29 AM
#3
Assuming you're already dealing with a raw transaction, the signrawtransaction command 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.
sr. member
Activity: 448
Merit: 252
May 26, 2013, 02:03:19 AM
#2
Assuming you're already dealing with a raw transaction, the signrawtransaction command 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.
hero member
Activity: 740
Merit: 501
May 26, 2013, 01:19:53 AM
#1
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?
Jump to: