Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Inaccuracy in dev guide for createrawtransaction #559

Closed
royalfork opened this Issue Sep 18, 2014 · 3 comments

Comments

Projects
None yet
3 participants

Location: https://bitcoin.org/en/developer-examples#simple-raw-transaction

I received a JSON parse error when following the guide's steps for creating a raw transaction.

Here's what happened on my machine:

~/.b/t/b/index ❯❯❯ bitcoin-cli -regtest listunspent                     ⏎
[
    {
        "txid" : "0b95cf0e1b6c9579e53ae147a497c49e635091f53aa996e7e27c87fce388cd0e",
        "vout" : 0,
        "address" : "mmZ2grFSzgrFCAs1Z2m91mLKgJkKQYnnho",
        "scriptPubKey" : "2102616d968e135f6e2488c5e45fb08c99838ad7f5ddd918d4d98a23a12b218fdc9bac",
        "amount" : 50.00000000,
        "confirmations" : 101
    },
    {
        "txid" : "c2b30d0a5aae70d138fba3496bbbd95cd4dffb25b98a096c5421e19f9dc38816",
        "vout" : 0,
        "address" : "mjUT9N2VaqyJ1xQkeraEWd7fu42ufCsAjr",
        "scriptPubKey" : "76a9142b6756910ee623e6d21116e7c334c08577b4fa0888ac",
        "amount" : 40.00000000,
        "confirmations" : 1
    },
    {
        "txid" : "c2b30d0a5aae70d138fba3496bbbd95cd4dffb25b98a096c5421e19f9dc38816",
        "vout" : 1,
        "address" : "mrhvdMRRcBeapkyrHjiYrCZQJSzwPXvLXw",
        "account" : "",
        "scriptPubKey" : "76a9147abc9143e394ba459bb9c5d55f5cf9471c29d78688ac",
        "amount" : 10.00000000,
        "confirmations" : 1
    }
]
~/.b/t/b/index ❯❯❯ bitcoin-cli -regtest createrawtransaction '''
    [
      {
        "txid": "0b95cf0e1b6c9579e53ae147a497c49e635091f53aa996e7e27c87fce388cd0e",
        "vout": 0
      }
    ]
    ''' '''
    {
      "mrhvdMRRcBeapkyrHjiYrCZQJSzwPXvLXw": 49.9999
    }'''
error: Error parsing JSON:'
    [
      {
        "txid": "0b95cf0e1b6c9579e53ae147a497c49e635091f53aa996e7e27c87fce388cd0e",
        "vout": 0
      }
    ]
    '

Here's what the documentation says:

bitcoin-cli -regtest createrawtransaction '''
[
{
"txid": "'$UTXO_TXID'",
"vout": '$UTXO_VOUT'
}
]
''' '''
{
"'$NEW_ADDRESS'": 49.9999
}'''
01000000017b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de
0398a14f3f0000000000ffffffff01f0ca052a010000001976a914cbc20a7664
f2f69e5355aa427045bc15e7c6c77288ac00000000

Contributor

harding commented Sep 18, 2014

@royalfork thanks for the report!

It looks like your shell is passing a single quote (') into the JSON. I used the bash shell on Linux to write the tutorial; may I ask what shell you're using? I just quickly tested the ash, tcsh, fish, and zsh shells, and all of them seem to work except tcsh (but I get a different error than you got).

You may want to try replacing series of three single quotes (''') with just one single quote ('). On bash, odd number of quotes in a row always act the same, so I used three quotes to delineate a code block---but just one single-quote should act the same.

If that doesn't work, then maybe try putting everything on the same line. This is what gets done in normal practice when formatting for publication isn't a concern. For example, here is the command you tried to run on one line:

bitcoin-cli -regtest createrawtransaction '[{ "txid": "0b95cf0e1b6c9579e53ae147a497c49e635091f53aa996e7e27c87fce388cd0e", "vout": 0 }]' '{ "mrhvdMRRcBeapkyrHjiYrCZQJSzwPXvLXw": 49.9999 }'

When we get this all sorted out, I'll update the introduction to the instructions with information to help others avoid this problem. Thanks!

Contributor

harding commented Sep 23, 2014

@royalfork I haven't heard back from you in a number of days, so I'm going to close this issue as I can't reproduce your error condition. If you have any more information to add after reading my reply above, please feel free to re-open this issue. Thanks!

@harding harding closed this Sep 23, 2014

@harding harding added the Dev Docs label Dec 13, 2014

Hiblet commented May 24, 2016 edited

I had the same issue in the DOS shell (boo! hiss!), eventually it came down to removing single quotes, and escaping double quotes... bitcoin-cli -regtest createrawtransaction [{"txid":"c6343009c5d73572f750359480ae95170a00cfb41063f8cd70e1c14d06e8776c","vout":0}] {"myf8U7KUzidun3WzjK2WM4nYVyE1ZkpSGH":49.9999}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment