Bitcoin Forum
May 03, 2024, 06:11:18 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Sign transaction across wallet  (Read 1229 times)
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 26, 2013, 05: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?








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


1714716678
Hero Member
*
Offline Offline

Posts: 1714716678

View Profile Personal Message (Offline)

Ignore
1714716678
Reply with quote  #2

1714716678
Report to moderator
In order to achieve higher forum ranks, you need both activity points and merit points.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
May 26, 2013, 06: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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 26, 2013, 11: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.








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4615



View Profile
May 26, 2013, 01:53:43 PM
 #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.
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
May 27, 2013, 12:28:41 AM
 #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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 27, 2013, 04: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?








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
May 27, 2013, 06: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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 28, 2013, 04: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?








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
May 29, 2013, 02:38:30 AM
 #9

Thanks!!

What did you pass as the second argument?

Null.  So
Code:
signrawtransaction <hex string> 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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
kodo
Newbie
*
Offline Offline

Activity: 42
Merit: 0



View Profile
May 29, 2013, 04:54:54 AM
 #10

hmm im not sure about this.
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 29, 2013, 06:05:52 PM
 #11

Thanks!!

What did you pass as the second argument?

Null.  So
Code:
signrawtransaction <hex string> 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








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


kodo
Newbie
*
Offline Offline

Activity: 42
Merit: 0



View Profile
May 29, 2013, 06:21:04 PM
 #12

Glad you got this worked out.
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 30, 2013, 12:50:42 PM
 #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?








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
May 30, 2013, 01:15:04 PM
 #14

Erm, I'm pretty sure you need to pass in an empty array there, and not the string "null".

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
madmadmax (OP)
Hero Member
*****
Offline Offline

Activity: 740
Merit: 501



View Profile
May 30, 2013, 02:43:33 PM
 #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.








       ▄▄▄▄▄               ▄▄▄▄▄
   ▄▄█▀▀▀▀▀▀██▄        ▄▄█▀▀▀▀▀▀▀█▄
 ▄██▀        ▀██▄    ▄██▀         ▀█▄
██▀            ▀██▄  ▀▀             ██
██               ▀██        ▄▄▄▄▄▄▄▄██
██                ▀██▄      ▀▀▀▀▀▀▀▀▀▀
 ██▄          ▄██   ▀██▄          ▄▄▄
  ▀██▄      ▄██▀      ▀██▄▄     ▄██▀
    ▀▀██████▀▀          ▀▀██████▀▀


Unchained Smart Contracts
Decentralized Oracle
Infinitly Scalable
Blockchain Technology
Turing-Complete
State-Channels



                 ▄████▄▄    ▄
██             ████████████▀
████▄         █████████████▀
▀████████▄▄   █████████████
▄▄█████████████████████████
██████████████████████████
  ▀██████████████████████
   █████████████████████
    ▀█████████████████▀
      ▄█████████████▀
▄▄███████████████▀
   ▀▀▀▀▀▀▀▀▀▀▀

             ▄██▄
     ▄      ▐████   ▄▄
   █████     ██████████
    █████████████████▀
 ▄████████████▀████▌
██████████     ▀████    
 ▀▀   █████     ██████████
      ▀████▌▄████████████▀
    ▄▄▄███████████████▌
   ██████████▀    ▐████
    ▀▀▀  ████▌     ▀▀▀
         ▀███▀
f


kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
May 30, 2013, 04:31:11 PM
 #16

Are you passing an empty array, or an empty string?

'[]'

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 254


View Profile WWW
May 30, 2013, 06: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"]]}

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!