Author

Topic: how to sign a transaction and not broadcast them? (Read 1831 times)

sr. member
Activity: 252
Merit: 250
girlbtc.com
September 22, 2016, 03:43:14 AM
#13

So the scriptpubkey for the output you're using is 76a91490c7eedb3d0d26faa21ade8372a456633e950ff488ac.

yes thx very much , it works

because my syn is not complete , I can not find the raw transaction  on my local bitcoind, and I use blockchain.info  https://blockchain.info/rawtx/  with this I get something called scrip

Code:

{
         "spent":false,
         "tx_index":176528120,
         "type":0,
         "addr":"16WuhEj27afT5YkvLoD6n3Ek1Md7TthQpX",
         "value":1318400,
         "n":1,
         "script":"76a9143c80ada6bef955d9f6bebaf28a8b9f71b4444d2288ac"
      }

and it is the same as the scriptpubkey   it works .

thx
hero member
Activity: 574
Merit: 503
V2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==
That's probably because you haven't synced up to the point where the input transactions shows up.

Try this:
Code:
signrawtransaction "hexstring" "[{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\"}]" "[\"privatekey\"]" "ALL"

^^That's what I was trying to do but keep getting parsing error. Didn't know I have to use "\" between quotes. This works without having to sync.

in my idea, the hexstring already have the info of  txid and vout.

and I don't know what is scriptPubKey  where to get it ?

Get the raw hex of 20f90f035cf6efb4c5ebb7c5c5f3459323f4b3ee9c9f2fdefa45d6d8e95d8e0c and decode it using decoderawtransaction.

In your case it would be:
Quote
0100000001fd0173e6af05ee6c36c970e6483edef1a30373a0a2244dc495aee7efdc58da7801000 0008b483045022100a308300f01eb5a349ccefb294475989e297eb83966a37620605da43d19d096 52022059790e9334e2da1f16de4b58d8623462d7b7c3559bd7479ecc41ba2ce8cafa25014104fef b5625a6c70cf33ca6b4e1ddea093e145410899c051bb6c85beff66532e57a074e8b249c5ebf5593 24162dc2ca6d8c1b5c3e2d986975c3dfd1b2b945e0ed09ffffffff02c0d40100000000001976a91 490c7eedb3d0d26faa21ade8372a456633e950ff488ac64a35601000000001976a914cc2866e100 23714b13e316d4dff34570ac9ff53b88ac00000000

Decode that and you'll get:
Quote
{
  "txid": "20f90f035cf6efb4c5ebb7c5c5f3459323f4b3ee9c9f2fdefa45d6d8e95d8e0c",
  "size": 258,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "78da58dcefe7ae95c44d24a2a07303a3f1de3e48e670c9366cee05afe67301fd",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100a308300f01eb5a349ccefb294475989e297eb83966a37620605da43d19d0965202205 9790e9334e2da1f16de4b58d8623462d7b7c3559bd7479ecc41ba2ce8cafa25[ALL] 04fefb5625a6c70cf33ca6b4e1ddea093e145410899c051bb6c85beff66532e57a074e8b249c5eb f559324162dc2ca6d8c1b5c3e2d986975c3dfd1b2b945e0ed09",
        "hex": "483045022100a308300f01eb5a349ccefb294475989e297eb83966a37620605da43d19d09652022 059790e9334e2da1f16de4b58d8623462d7b7c3559bd7479ecc41ba2ce8cafa25014104fefb5625 a6c70cf33ca6b4e1ddea093e145410899c051bb6c85beff66532e57a074e8b249c5ebf559324162 dc2ca6d8c1b5c3e2d986975c3dfd1b2b945e0ed09"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00120000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 90c7eedb3d0d26faa21ade8372a456633e950ff4 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a91490c7eedb3d0d26faa21ade8372a456633e950ff488ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1ECXpDRh4tzva6EUViV8pmpHYAvsCo9mzE"
        ]
      }
    },
    {
      "value": 0.22455140,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 cc2866e10023714b13e316d4dff34570ac9ff53b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914cc2866e10023714b13e316d4dff34570ac9ff53b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1KcVFJffbe63xsZ631evetdkLvXgFp7N5r"
        ]
      }
    }
  ]
}

So the scriptpubkey for the output you're using is 76a91490c7eedb3d0d26faa21ade8372a456633e950ff488ac.
sr. member
Activity: 252
Merit: 250
girlbtc.com
That's probably because you haven't synced up to the point where the input transactions shows up.

Try this:
Code:
signrawtransaction "hexstring" "[{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\"}]" "[\"privatekey\"]" "ALL"

^^That's what I was trying to do but keep getting parsing error. Didn't know I have to use "\" between quotes. This works without having to sync.

in my idea, the hexstring already have the info of  txid and vout.

and I don't know what is scriptPubKey  where to get it ?
hero member
Activity: 574
Merit: 503
V2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==
That's probably because you haven't synced up to the point where the input transactions shows up.

Try this:
Code:
signrawtransaction "hexstring" "[{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\"}]" "[\"privatekey\"]" "ALL"

^^That's what I was trying to do but keep getting parsing error. Didn't know I have to use "\" between quotes. This works without having to sync.
sr. member
Activity: 252
Merit: 250
girlbtc.com
following is my steps, what am I missing?

Step1:
Quote
createrawtransaction "[{\"txid\":\"20f90f035cf6efb4c5ebb7c5c5f3459323f4b3ee9c9f2fdefa45d6d8e95d8e0c\",\"vout\":0}]" "{\"1JzePMePtBC6ufpSJpJAWbsbWX26uCo6og\":0.0011}"

and I get the result
Quote
01000000010c8e5de9d8d645fade2f9f9ceeb3f4239345f3c5c5b7ebc5b4eff65c030ff92000000 00000ffffffff01b0ad0100000000001976a914c5610e527a31f2a2333472d1501b600ed412f958 88ac00000000

Step 2:
Quote
signrawtransaction 01000000010c8e5de9d8d645fade2f9f9ceeb3f4239345f3c5c5b7ebc5b4eff65c030ff92000000 00000ffffffff01b0ad0100000000001976a914c5610e527a31f2a2333472d1501b600ed412f958 88ac00000000

and I get
Quote

{
  "hex": "01000000010c8e5de9d8d645fade2f9f9ceeb3f4239345f3c5c5b7ebc5b4eff65c030ff92000000 00000ffffffff01b0ad0100000000001976a914c5610e527a31f2a2333472d1501b600ed412f958 88ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "20f90f035cf6efb4c5ebb7c5c5f3459323f4b3ee9c9f2fdefa45d6d8e95d8e0c",
      "vout": 0,
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Input not found or already spent"
    }
  ]
}

seems something wrong happened

and I sendrawtransaction

the reply is Missing inputs (code -25)

what's wrong with me?thx
sr. member
Activity: 252
Merit: 250
girlbtc.com
If you have just the unsigned transaction, you will need to be synced in order to sign.

Correct.

It is impossible to sign with "just the unsigned transaction".  You also MUST have the scriptPubKey of the output being spent (and the redeem script of any P2SH output that is being spent).  If you haven't saved the scriptPubKey with the transaction, then Bitcoin Core can acquire it by synchronizing the blockchain.

Bitcoin Core should have saved locally the redeem script for any P2SH address that it generated, but if you generated the P2SH address elsewhere, then you'll need the redeem script. Bitcoin Core will not typically be able to acquire that through synchronizing.

If you have saved all the scriptPubKey from all the outputs being spent as inputs in the transaction, and you or your Bitcoin Core have any necessary redeem scripts (from addresses that start with a 3) then you can sign without being synchronized.

In order to sign a transaction you need the following:
  • The transaction to sign
  • All the scriptPubKeys of all the inputs
  • All the redeem scripts of any P2SH inputs
  • The necessary private keys

As long as you have all of those, you can sign offline with Bitcoin Core without being synchronized.



very good and detialed ,far more question what is the scriptPubK,for exmaple this trans

Code:
{
   "ver":1,
   "inputs":[
      {
         "sequence":4294967295,
         "prev_out":{
            "spent":true,
            "tx_index":176269511,
            "type":0,
            "addr":"1KcVFJffbe63xsZ631evetdkLvXgFp7N5r",
            "value":22587570,
            "n":1,
            "script":"76a914cc2866e10023714b13e316d4dff34570ac9ff53b88ac"
         },
         "script":"483045022100a308300f01eb5a349ccefb294475989e297eb83966a37620605da43d19d09652022059790e9334e2da1f16de4b58d8623462d7b7c3559bd7479ecc41ba2ce8cafa25014104fefb5625a6c70cf33ca6b4e1ddea093e145410899c051bb6c85beff66532e57a074e8b249c5ebf559324162dc2ca6d8c1b5c3e2d986975c3dfd1b2b945e0ed09"
      }
   ],
   "block_height":430762,
   "relayed_by":"127.0.0.1",
   "out":[
      {
         "spent":false,
         "tx_index":176449270,
         "type":0,
         "addr":"1ECXpDRh4tzva6EUViV8pmpHYAvsCo9mzE",
         "value":120000,
         "n":0,
         "script":"76a91490c7eedb3d0d26faa21ade8372a456633e950ff488ac"
      },
      {
         "spent":true,
         "tx_index":176449270,
         "type":0,
         "addr":"1KcVFJffbe63xsZ631evetdkLvXgFp7N5r",
         "value":22455140,
         "n":1,
         "script":"76a914cc2866e10023714b13e316d4dff34570ac9ff53b88ac"
      }
   ],
   "lock_time":0,
   "size":258,
   "double_spend":false,
   "time":1474430490,
   "tx_index":176449270,
   "vin_sz":1,
   "hash":"20f90f035cf6efb4c5ebb7c5c5f3459323f4b3ee9c9f2fdefa45d6d8e95d8e0c",
   "vout_sz":2
}
legendary
Activity: 3472
Merit: 4801
If you have just the unsigned transaction, you will need to be synced in order to sign.

Correct.

It is impossible to sign with "just the unsigned transaction".  You also MUST have the scriptPubKey of the output being spent (and the redeem script of any P2SH output that is being spent).  If you haven't saved the scriptPubKey with the transaction, then Bitcoin Core can acquire it by synchronizing the blockchain.

Bitcoin Core should have saved locally the redeem script for any P2SH address that it generated, but if you generated the P2SH address elsewhere, then you'll need the redeem script. Bitcoin Core will not typically be able to acquire that through synchronizing.

If you have saved all the scriptPubKey from all the outputs being spent as inputs in the transaction, and you or your Bitcoin Core have any necessary redeem scripts (from addresses that start with a 3) then you can sign without being synchronized.

In order to sign a transaction you need the following:
  • The transaction to sign
  • All the scriptPubKeys of all the inputs
  • All the redeem scripts of any P2SH inputs
  • The necessary private keys

As long as you have all of those, you can sign offline with Bitcoin Core without being synchronized.
hero member
Activity: 574
Merit: 503
V2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==
If you don't have a fully synced bitcoin core you can also use a 3rd party service like coinb.in that will let you go through all the steps of a raw transaction. So you can create, sign and broadcast, or in your case create, sign and not broadcast.

You don't need to be synced to sign a transaction with bitcoin core. You can even sign offline.
If you have just the unsigned transaction, you will need to be synced in order to sign. This is because the scriptPubKey of the output being spent is put inside the scriptsig for signing purposes. Software made specifically for offline signing will include that data in some way so that a sync is not needed.

Oh, sorry I didn't know that. I've signed some transactions offline with core so I thought we don't need to sync. I guess since it works offline it means we only need to sync up to the point when the transaction shows up in the blockchain.

This is weird though (took it from the error message that appears when you enter signrawtransaction without hex):
Quote
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )

Sign inputs for raw transaction (serialized, hex-encoded).
The second optional argument (may be null) is an array of previous transaction outputs that
this transaction depends on but may not yet be in the block chain.

The 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.

It sounds like it's possible to do it with non-existing outputs. I tried it but always get a parsing error no matter what I do.
staff
Activity: 3458
Merit: 6793
Just writing some code
If you don't have a fully synced bitcoin core you can also use a 3rd party service like coinb.in that will let you go through all the steps of a raw transaction. So you can create, sign and broadcast, or in your case create, sign and not broadcast.

You don't need to be synced to sign a transaction with bitcoin core. You can even sign offline.
If you have just the unsigned transaction, you will need to be synced in order to sign. This is because the scriptPubKey of the output being spent is put inside the scriptsig for signing purposes. Software made specifically for offline signing will include that data in some way so that a sync is not needed.
hero member
Activity: 574
Merit: 503
V2h5IGFyZSB5b3UgcmVhZGluZyB0aGlzPw==
If you don't have a fully synced bitcoin core you can also use a 3rd party service like coinb.in that will let you go through all the steps of a raw transaction. So you can create, sign and broadcast, or in your case create, sign and not broadcast.

You don't need to be synced to sign a transaction with bitcoin core. You can even sign offline.
legendary
Activity: 1442
Merit: 1186
If you don't have a fully synced bitcoin core you can also use a 3rd party service like coinb.in that will let you go through all the steps of a raw transaction. So you can create, sign and broadcast, or in your case create, sign and not broadcast.
staff
Activity: 3458
Merit: 6793
Just writing some code
Using Bitcoin Core, you can go to the debug console and sign a raw transaction with signrawtransaction. It will give you the raw hex for the transaction which can be broadcast, but does not need to.
sr. member
Activity: 252
Merit: 250
girlbtc.com
is that complex?

thx
Jump to: