Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: isis on August 29, 2012, 08:50:21 PM



Title: Raw Transactions API... Am I using it correctly?
Post by: isis on August 29, 2012, 08:50:21 PM
Hi all,

I've been trying to work with the raw transactions API since it's crucial to something I'm working on and I'm encountering a problem.
Code:
createrawtransaction [{"txid":eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac,"vout":0}] {1FQvMNzFJRf2nFJbhri2pWEVMqTtdLSCmA:2336129790}

As far as I can tell the above should work, but when I put it into the debug console I get the following error.
Code:
Error: Error parsing JSON:[{txid:eb63d5d53cd906b5cf75a014e1bcf1c0198ae58f378d45dbfa15045ac89a38ac,vout:0}]

I've a hunch I'm calling it wrong, however it looks well formed to me so I'm at a loss.

I'm using v0.7.0rc1-beta

Thanks for any information!


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: Gavin Andresen on August 29, 2012, 08:53:50 PM
Using bitcoind on a command-line?  What operating system?

Something is stripping off the double-quotes from the "txid" and "vout" keys before it gets to bitcoind.  If you're using bash on linux, then put single quotes around the arguments.  Like this:

Code:
createrawtransaction '[{"txid":eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac,"vout":0}]' '{"1FQvMNzFJRf2nFJbhri2pWEVMqTtdLSCmA":23.36129790}'

I also corrected the second argument, the address is a string (strings in JSON are always "whatever") and the amount is decimal number-of-bitcoins.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: gmaxwell on August 29, 2012, 09:28:35 PM
put it into the debug console
There is a quoting bug with the debug console, see page 2 of the 0.7.0rc1 thread for details on a workaround.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: isis on August 30, 2012, 03:27:49 AM
put it into the debug console
There is a quoting bug with the debug console, see page 2 of the 0.7.0rc1 thread for details on a workaround.

Followed the instructions in that thread which amounts to escaping all your quotes in the debug console and it's the same issue but at least it's not stripping the quotes anymore.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: isis on August 30, 2012, 03:44:52 AM
put it into the debug console
There is a quoting bug with the debug console, see page 2 of the 0.7.0rc1 thread for details on a workaround.

Followed the instructions in that thread which amounts to escaping all your quotes in the debug console and it's the same issue but at least it's not stripping the quotes anymore.

I don't think this is an issue with the debug console.  I tried it from the command line both with and without escaping the quotes and I'm still getting the same issue.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: gmaxwell on August 30, 2012, 03:58:23 AM
Followed the instructions in that thread which amounts to escaping all your quotes in the debug console and it's the same issue but at lea
I don't think this is an issue with the debug console.  I tried it from the command line both with and without escaping the quotes and I'm still getting the same issue.

Works fine for me:
Code:
$ ./bitcoind createrawtransaction '[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]' '{"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB":23.35}'
0100000001ac389ac85a0415fadb458d378de58a19c0f1bce114a075cfb506d93cd5d563eb0000000000ffffffff01c0452d8b000000001976a914a86e8ee2a05a44613904e18132e49b2448adc4e688ac00000000
Feel free to sign and submit if you have any doubt. :P (though I don't seem to have that input in my mempool or blockchain)


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: marcus_of_augustus on August 30, 2012, 04:43:22 AM
Tagged.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: Diapolo on August 30, 2012, 05:01:31 AM
If you are using Windows replace the '-char with \".

Dia


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: isis on August 30, 2012, 01:41:55 PM
Followed the instructions in that thread which amounts to escaping all your quotes in the debug console and it's the same issue but at lea
I don't think this is an issue with the debug console.  I tried it from the command line both with and without escaping the quotes and I'm still getting the same issue.

Works fine for me:
Code:
$ ./bitcoind createrawtransaction '[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]' '{"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB":23.35}'
0100000001ac389ac85a0415fadb458d378de58a19c0f1bce114a075cfb506d93cd5d563eb0000000000ffffffff01c0452d8b000000001976a914a86e8ee2a05a44613904e18132e49b2448adc4e688ac00000000
Feel free to sign and submit if you have any doubt. :P (though I don't seem to have that input in my mempool or blockchain)


There are some significant differences between what I pasted and this one.
First is the use of ' to wrap the parameters.  Second is the quoting of both the keys and the values in the txid/vout pairs whereas I only had the keys quoted.  Finally you've quoted the send to address.

Nevertheless even a copy and paste of your command straight into the command prompt, or the debug console doesn't work here, same JSON parsing error in both instances.  

I also tried to replace ' with \" to see if that would work and it's the same error.

I'm curious, are you running the RC1 or something built from sources?  

Here are my relevant system specs.
Windows Vista SP2 64bit
Bitcoin version v0.7.0rc1-beta


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: gmaxwell on August 30, 2012, 02:53:28 PM
There are some significant differences between what I pasted and this one.
First is the use of ' to wrap the parameters.  Second is the quoting of both the keys and the values in the txid/vout pairs whereas I only had the keys quoted.  Finally you've quoted the send to address.
Yes, and I asked you to see the other thread for the workaround quoting pattern for the debug console. Diapolo provided the quoting style for windows hereó you didn't specify what OS you were on before.  I tested that on RC1 just for you.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: Gavin Andresen on August 30, 2012, 04:02:58 PM
Disclaimer: I don't do Windows.

But according to a quick google search, caret is the Windows cmd.exe escape character, and [] and {} are NOT special characters to cmd.exe.

So maybe this?

Code:
bitcoind.exe createrawtransaction [{^"txid^":^"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac^",^"vout^":0}] {^"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB^":23.35}


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: CIYAM on August 30, 2012, 04:10:40 PM
So maybe this?

Code:
C:\Bin>args  [{^"txid^":^"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac^",^"vout^":0}] {^"1GMaxweLLbo8md
XvnnC19Wt2wigiYUKgEB^":23.35}
arg[ 0 ] = 'C:\Bin\args.exe'
arg[ 1 ] = '[{txid:eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac,vout:0}]'
arg[ 2 ] = '{1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB:23.35}'

Tested the argument parsing using a small test program I wrote for Windows - it looks to me like that should do the trick.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: Gavin Andresen on August 30, 2012, 04:12:48 PM
mmm, no.

To be valid JSON, arg[1] must be:
Code:
[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]

WTF is Windows doing with the arguments?


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: isis on August 30, 2012, 04:13:10 PM
Disclaimer: I don't do Windows.

But according to a quick google search, caret is the Windows cmd.exe escape character, and [] and {} are NOT special characters to cmd.exe.

So maybe this?

Code:
bitcoind.exe createrawtransaction [{^"txid^":^"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac^",^"vout^":0}] {^"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB^":23.35}


Frankly I'm not a big windows fan either, but it's what I've got to work with for the time being.
That was a great suggestion, but it didn't work either
Code:
bitcoind.exe createrawtransaction [{^"txid^":^"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac^",^"vout^":0}]{^"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB^":23.35}
Produces the same...
Code:
error: Error parsing JSON:[{txid:eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45d
bfa15045ac89a38ac,vout:0}]


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: CIYAM on August 30, 2012, 04:17:31 PM
WTF is Windows doing with the arguments?

Okay - well to get my program to do that I changed the input to this:

Code:
C:\bin>args "[{\"txid\":\"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac\",\"vout\":0}]" "{\"1GMaxweLLbo8mdXvnnC19
Wt2wigiYUKgEB\":23.35}"
arg[ 0 ] = 'C:\bin\args.exe'
arg[ 1 ] = '[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]'
arg[ 2 ] = '{"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB":23.35}'

(without a doubt quote characters are a huge PITA with Windows console and batch file calls)

Also this is the source of the "args" program I am using:
Code:
#include <iostream>

using namespace std;

int main( int argc, char* argv[ ] )
{
   for( int i = 0; i < argc; i++ )
      cout << "arg[ " << i << " ] = '" << argv[ i ] << "'\n";
}

(I wrote this program due to many such issues I've encountered before)


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: isis on August 30, 2012, 04:38:21 PM
WTF is Windows doing with the arguments?

Okay - well to get my program to do that I changed the input to this:

Code:
C:\bin>args "[{\"txid\":\"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac\",\"vout\":0}]" "{\"1GMaxweLLbo8mdXvnnC19
Wt2wigiYUKgEB\":23.35}"
arg[ 0 ] = 'C:\bin\args.exe'
arg[ 1 ] = '[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]'
arg[ 2 ] = '{"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB":23.35}'

(without a doubt quote characters are a huge PITA with Windows console and batch file calls)

Also this is the source of the "args" program I am using:
Code:
#include <iostream>

using namespace std;

int main( int argc, char* argv[ ] )
{
   for( int i = 0; i < argc; i++ )
      cout << "arg[ " << i << " ] = '" << argv[ i ] << "'\n";
}

(I wrote this program due to many such issues I've encountered before)


That one worked, thank you!


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: CIYAM on August 30, 2012, 05:14:50 PM
That one worked, thank you!

Most welcome - as stated quote stuff with Windows console/batch really sucks bad (that's why I wrote the utility to help me with such problems).

:)


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: shamoons on July 25, 2013, 02:13:02 PM
mmm, no.

To be valid JSON, arg[1] must be:
Code:
[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]

WTF is Windows doing with the arguments?

How are you deciding the txid?


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: CIYAM on July 25, 2013, 02:18:26 PM
How are you deciding the txid?

The txid for each "input" comes from the UTXOs (i.e. "listunspent") and the txid of the final raw tx is returned to you by bitcoind when it is successfully sent.


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: alexrossi on December 23, 2013, 08:11:56 PM
WTF is Windows doing with the arguments?

Okay - well to get my program to do that I changed the input to this:

Code:
C:\bin>args "[{\"txid\":\"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac\",\"vout\":0}]" "{\"1GMaxweLLbo8mdXvnnC19
Wt2wigiYUKgEB\":23.35}"
arg[ 0 ] = 'C:\bin\args.exe'
arg[ 1 ] = '[{"txid":"eb63d5d53cd906b5cf75a014e1bcf1c0198ae58d378d45dbfa15045ac89a38ac","vout":0}]'
arg[ 2 ] = '{"1GMaxweLLbo8mdXvnnC19Wt2wigiYUKgEB":23.35}'

(without a doubt quote characters are a huge PITA with Windows console and batch file calls)

Also this is the source of the "args" program I am using:
Code:
#include <iostream>

using namespace std;

int main( int argc, char* argv[ ] )
{
   for( int i = 0; i < argc; i++ )
      cout << "arg[ " << i << " ] = '" << argv[ i ] << "'\n";
}

(I wrote this program due to many such issues I've encountered before)


Worked also for me!!! many thanks  :)


Title: Re: Raw Transactions API... Am I using it correctly?
Post by: Hiblet on May 24, 2016, 03:17:51 PM
I'm a DOS person, I had a lot of faffing about but this worked for me...

bitcoin-cli -regtest createrawtransaction [{\"txid\":\"c6343009c5d73572f750359480ae95170a00cfb41063f8cd70e1c14d06e8776c\",\"vout\":0}] {\"myf8U7KUzidun3WzjK2WM4nYVyE1ZkpSGH\":49.9999}

I removed single quotes around each object, and double quotes within the object had to be escaped.  Hope this helps anyone else getting JSON Parse errors on the Windows DOS command line version.  The actual ids and addresses are my own, natch, yours will differ, but the formatting should work.