Bitcoin Forum
May 30, 2024, 06:48:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: create a transaction offline and sign it offline (redeemScript)  (Read 997 times)
Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 03, 2016, 07:15:04 PM
Last edit: November 03, 2016, 09:47:59 PM by Armin van Bruggen
 #1

how to sign this transaction offline?

Bitcoins received from:

https://www.blocktrail.com/tBTC/tx/6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164

TXID= 6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164
amount: 10
received to address: mgnKCYotzvX9gK36vZEd86WJMN8bdtB1sF

Code:
createrawtransaction '[{"txid":"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164","vout":1}]' '{"2N4ofFPCXk7NMRduBc59bPnM2CksXdk9964":0.1}'

returns:

Code:
010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000

decode it (to get vout hex)

Code:
decoderawtransaction 010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000

returns:

Code:
 {
     "txid" : "04c557d38051d1450ff501520b1d7895c127543b435ee34e8bb76da4139f2e4b",
     "version" : 1,
     "locktime" : 0,
     "vin" : [
         {
             "txid" : "6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164",
             "vout" : 1,
             "scriptSig" : {
                 "asm" : "",
                 "hex" : ""
             },
             "sequence" : 4294967295
         }
     ],
     "vout" : [
         {
             "value" : 0.10000000,
             "n" : 0,
             "scriptPubKey" : {
                 "asm" : "OP_HASH160 7ecbc7d9cbb793ffb9a2905876c49f19cef8f75a OP_EQUAL",
                 "hex" : "a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87",
                 "reqSigs" : 1,
                 "type" : "scripthash",
                 "addresses" : [
                     "2N4ofFPCXk7NMRduBc59bPnM2CksXdk9964"
                 ]
             }
         }
     ]
 }

get private key of address

Code:
dumpprivkey mgnKCYotzvX9gK36vZEd86WJMN8bdtB1sF

returns:

Code:
XXX

sign it:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"XXX\", ,\"redeemScript\":\""]" "ALL"

Running this returns all the time just an input on my server. When I hit enter nothing happens:
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 03, 2016, 07:21:31 PM
 #2

sign it:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"XXX\", ,\"redeemScript\":\""]" "ALL"
This is incorrect. The scriptPubkey is not the private key. The scriptPubKey is the hex of the output script that you are spending from. You are also missing the parameter for the private key array that goes right before the sighash parameter. Even if you don't need that parameter (i.e the key is in your wallet), you still need to specify it if you are going to have the sighash parameter as well.

If the transaction you are spending from is in your wallet, you do not need anything except the hex of the unsigned transaction. The rest will be automatically filled in for you.

Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 03, 2016, 07:24:37 PM
 #3

sign it:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"XXX\", ,\"redeemScript\":\""]" "ALL"
This is incorrect. The scriptPubkey is not the private key. The scriptPubKey is the hex of the output script that you are spending from. You are also missing the parameter for the private key array that goes right before the sighash parameter. Even if you don't need that parameter (i.e the key is in your wallet), you still need to specify it if you are going to have the sighash parameter as well.

If the transaction you are spending from is in your wallet, you do not need anything except the hex of the unsigned transaction. The rest will be automatically filled in for you.

I updated to:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" "ALL"

What is missing now and where to insert?
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 03, 2016, 07:26:35 PM
 #4

I updated to:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" "ALL"

What is missing now and where to insert?

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" '["<privkey>"]' "ALL"
where <privkey> is the private key.

Also, protip. Use a single quote to wrap all the JSON stuff and you won't need to escape the double quotes since they are all read as literals.

Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 03, 2016, 07:29:21 PM
 #5

I updated to:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" "ALL"

What is missing now and where to insert?

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" '["<privkey>"]' "ALL"
where <privkey> is the private key.

Also, protip. Use a single quote to wrap all the JSON stuff and you won't need to escape the double quotes since they are all read as literals.

still the same problem:

achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 03, 2016, 07:36:05 PM
 #6

I updated to:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" "ALL"

What is missing now and where to insert?

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" '["<privkey>"]' "ALL"
where <privkey> is the private key.

Also, protip. Use a single quote to wrap all the JSON stuff and you won't need to escape the double quotes since they are all read as literals.

still the same problem:


You have an unclosed quote somewhere.

Edit: This is your fixed command:
Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\"]" '["<privkey>"]' "ALL"

Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 03, 2016, 07:41:38 PM
 #7

I updated to:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" "ALL"

What is missing now and where to insert?

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\", ,\"redeemScript\":\""]" '["<privkey>"]' "ALL"
where <privkey> is the private key.

Also, protip. Use a single quote to wrap all the JSON stuff and you won't need to escape the double quotes since they are all read as literals.

still the same problem:


You have an unclosed quote somewhere.

Edit: This is your fixed command:
Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\"]" '["<privkey>"]' "ALL"

This now shows:

Code:
error: Error parsing JSON:[{"txid":"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164","vout":1,"scriptPubKey":"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87"]
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 03, 2016, 09:19:08 PM
 #8

Oops. Forgot a bracket. This should work.

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\"}]" '["<privkey>"]' "ALL"

Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 03, 2016, 09:23:03 PM
Last edit: November 03, 2016, 09:43:53 PM by Armin van Bruggen
 #9

Oops. Forgot a bracket. This should work.

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\"}]" '["<privkey>"]' "ALL"

using this code:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\",\"redeemScript\":\"\"}]" '["xxx"]' "ALL"

it shows:

Code:
error: {"code":-8,"message":"redeemScript must be hexadecimal string (not '')"}

What should I use as value for redeemScript?
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3402
Merit: 6659


Just writing some code


View Profile WWW
November 03, 2016, 09:58:33 PM
Last edit: November 03, 2016, 10:15:11 PM by achow101
 #10

using this code:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\",\"redeemScript\":\"\"}]" '["xxx"]' "ALL"

it shows:

Code:
error: {"code":-8,"message":"redeemScript must be hexadecimal string (not '')"}

What should I use as value for redeemScript?
redeemScript should be blank. Also, you need the amount field, I forgot about that.

Something's wrong with your command. I need to look a bit into it some more.

Edit: I found the problem. The scriptPubKey is the scriptPubKey of the output that you are spending from, not the one you are spending to. It should be 76a90ddfd0dee20dbe590f70298817810acc0c3c955888ac

Armin van Bruggen (OP)
Full Member
***
Offline Offline

Activity: 232
Merit: 101


Stratege, berechnend


View Profile
November 04, 2016, 05:38:48 AM
 #11

using this code:

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a87\",\"redeemScript\":\"\"}]" '["xxx"]' "ALL"

it shows:

Code:
error: {"code":-8,"message":"redeemScript must be hexadecimal string (not '')"}

What should I use as value for redeemScript?
redeemScript should be blank. Also, you need the amount field, I forgot about that.

Something's wrong with your command. I need to look a bit into it some more.

Edit: I found the problem. The scriptPubKey is the scriptPubKey of the output that you are spending from, not the one you are spending to. It should be 76a90ddfd0dee20dbe590f70298817810acc0c3c955888ac

This

Code:
signrawtransaction "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000" "[{\"txid\":\"6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164\",\"vout\":1,\"scriptPubKey\":\"76a90ddfd0dee20dbe590f70298817810acc0c3c955888ac\",\"redeemScript\":\"\"}]" '["xxx"]' "ALL"

 now returns:

Code:
{
    "hex" : "010000000164518c0612559b8b47af331be4b33741ebed40298ce1df557e99e8955c0371690100000000ffffffff01809698000000000017a9147ecbc7d9cbb793ffb9a2905876c49f19cef8f75a8700000000",
    "complete" : false,
    "errors" : [
        {
            "txid" : "6971035c95e8997e55dfe18c2940edeb4137b3e41b33af478b9b5512068c5164",
            "vout" : 1,
            "scriptSig" : "",
            "sequence" : 4294967295,
            "error" : "Operation not valid with the current stack size"
        }
    ]
}

What did I wrong this time Sad?
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!