Unable to create raw transaction with json-rpc command

0

0

I am trying create a coinbase transaction with the command:

{"jsonrpc": "1.0", "id":"jsonrpc", "method":"createrawtransaction", "params":[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0xFFFFFFFF}] {1Ka3q3DVTBNBo2c4kVGMNzbd32RARV1FbA:25.00} }

but I am getting the following response:

{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

the same happens when I try with:

{"jsonrpc": "1.0", "id":"jsonrpc", "method":"createrawtransaction", "params":[{"txid":0000000000000000000000000000000000000000000000000000000000000000,"vout":0xFFFFFFFF}] {1Ka3q3DVTBNBo2c4kVGMNzbd32RARV1FbA:25.00} }

when I use the Debug window (in the bitcoin-qt application), I get Error: Error parsing JSON:[{txid:0000000000000000000000000000000000000000000000000000000000000000 and Method not found (code -32601) respectively.

Someone can tell what's wrong here?

Kleber Mota

Posted 2017-08-26T17:31:19.087

Reputation: 131

Answers

2

Here is the correct json:
createrawtransaction '[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":0}]' '{"1Ka3q3DVTBNBo2c4kVGMNzbd32RARV1FbA":12.5}'

I used 0for vout, because it has to be numeric (I don't believe hex is accepted).

help createrawtransaction


createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime )

Create a transaction spending the given inputs and creating new outputs.
Outputs can be addresses or data.
Returns hex-encoded raw transaction.
Note that the transaction's inputs are not signed, and
it is not stored in the wallet or transmitted to the network.

Arguments:
1. "inputs"                (array, required) A json array of json objects
     [
       {
         "txid":"id",    (string, required) The transaction id
         "vout":n,         (numeric, required) The output number
         "sequence":n      (numeric, optional) The sequence number
       } 
       ,...
     ]
2. "outputs"               (object, required) a json object with outputs
    {
      "address": x.xxx,    (numeric or string, required) The key is the bitcoin address, the numeric value (can be string) is the BTC amount
      "data": "hex"      (string, required) The key is "data", the value is hex encoded data
      ,...
    }
3. locktime                  (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs

Result:
"transaction"              (string) hex string of the transaction

Examples:
> bitcoin-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"address\":0.01}"
> bitcoin-cli createrawtransaction "[{\"txid\":\"myid\",\"vout\":0}]" "{\"data\":\"00010203\"}"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"address\":0.01}"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": ["[{\"txid\":\"myid\",\"vout\":0}]", "{\"data\":\"00010203\"}"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

Albert s

Posted 2017-08-26T17:31:19.087

Reputation: 1 344

Ok, that works! Just a last question: Do i need use sendtransaction and signrawtransaction for this transaction too? How/Where you get this help text for the command?Kleber Mota 2017-08-27T11:35:38.987

The help is from Bitcoin Core client console. I don't think you can sign that transaction, and I believe it needs to be included in a solved block, in order to be valid.Albert s 2017-08-29T08:23:05.137

0

Below Curl request worked perfect to me,

curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params": [[{\"txid\":\"myid\",\"vout\":0}], [{\"address\":0.01}]] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

Without Double quote (") inside the "params".

Shyamin Navoda

Posted 2017-08-26T17:31:19.087

Reputation: 1