4

I'm trying to create a raw transaction using Bitcoin Core v0.10.0 (on Windows 7 x64, and with txindex=1 optioned).

Bitcoin Core v0.10.0 comes with a new Bitcoin-tx executable utility. The help menu is as follows (under Windows 7 x64):

Bitcoin Core bitcoin-tx utility version v0.10.0

Usage:
  bitcoin-tx [options] <hex-tx> [commands]  Update hex-encoded bitcoin transaction
  bitcoin-tx [options] -create [commands]   Create hex-encoded bitcoin transaction

Options:
  -?                      This help message
  -create                 Create new, empty TX.
  -json                   Select JSON output
  -txid                   Output only the hex-encoded transaction id of the resultant transaction.
  -regtest                Enter regression test mode, which uses a special chain in which blocks can be solved instantly.
  -testnet                Use the test network

Commands:
  delin=N                Delete input N from TX
  delout=N               Delete output N from TX
  in=TXID:VOUT           Add input to TX
  locktime=N             Set TX lock time to N
  nversion=N             Set TX version to N
  outaddr=VALUE:ADDRESS  Add address-based output to TX
  outscript=VALUE:SCRIPT Add raw script output to TX
  sign=SIGHASH-FLAGS     Add zero or more signatures to transaction
      This command requires JSON registers:
      prevtxs=JSON object
      privatekeys=JSON object
      See signrawtransaction docs for format of sighash flags, JSON objects.

Register Commands:
  load=NAME:FILENAME     Load JSON file FILENAME into register NAME
  set=NAME:JSON-STRING   Set register NAME to given JSON-STRING

Using Windows CLI, I'm running into issues with createrawtransaction as it's not parsing the command the same as it does in the Bitcoin-QT console window.

bitcoin-cli createrawtransaction [{"txid":"dbdc2e2c7f143af70c5e7e8725f55d226b3c058d7bf34a303091b3c6a514848c","vout":1}] {"1BCi1L25GC9hUSvtSyGjmEvSyywoYubk4P":0.00011}

Gives error: Error parsing JSON:[{txid:dbdc2e2c7f143af70c5e7e8725f55d226b3c058d7bf34a303091b3c6a514848c,vout:1}]

Likewise, the bitcoin-tx utility won't work with this:

bitcoin-tx.exe -create in=dbdc2e2c7f143af70c5e7e8725f55d226b3c058d7bf34a303091b3c6a514848c:1 locktime=0 nversion=1 outaddr=2000:1BCi1L25GC9hUSvtSyGjmEvSyywoYubk4P outscript=0:687474703a2f2f676f6f2e676c2f7869556243555

How can I create a raw transaction using Bitcoin-cli and bitcoin-tx?

1
  • When Bitcoin emits Error parsing JSON:, it give you the token that confused it, exactly as it got it. Is your shell eating your " characters?
    – Nick ODell
    Feb 20, 2015 at 4:04

1 Answer 1

3

For the first command, you need to include the JSON in single quotes, like so:

$ bitcoin-cli createrawtransaction '[{"txid":"dbdc2e2c7f143af70c5e7e8725f55d226b3c058d7bf34a303091b3c6a514848c","vout":1}]' '{"1BCi1L25GC9hUSvtSyGjmEvSyywoYubk4P":0.00011}'
01000000018c8414a5c6b39130304af37b8d053c6b225df525877e5e0cf73a147f2c2edcdb0100000000ffffffff01f82a0000000000001976a9146fe8102ebe0fccb56de43ec82601ba16c68496af88ac00000000

The bitcoin-tx utility uses a shorthand that is deployed in the bitcoin unit tests. This example might help you use this command:

$ ./bitcoin-tx -create in=0fb9df5614be8b33be0434ce4062750d83f1b7ce05cc1296604f82eb9abf802b:0 outscript=0.00159999:"DUP HASH160 0x14 0x6793a38f79b8cd51dbb6face6dc75a4af5c1bf29 EQUALVERIFY CHECKSIG"
01000000012b80bf9aeb824f609612cc05ceb7f1830d756240ce3404be338bbe1456dfb90f0000000000ffffffff01ff700200000000001976a9146793a38f79b8cd51dbb6face6dc75a4af5c1bf2988ac00000000

The code for parsing the scripts can be found here. However, I find just looking at some examples in the unit test data to be helpful as well.

1
  • 1
    For DOS, you need to remove single quotes and escape double quotes... bitcoin-cli -regtest createrawtransaction [{\"txid\":\"c6343009c5d73572f750359480ae95170a00cfb41063f8cd70e1c14d06e8776c\",\"vout\":0}] {\"myf8U7KUzidun3WzjK2WM4nYVyE1ZkpSGH\":49.9999} May 24, 2016 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.