Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: michelemm on February 27, 2016, 03:28:21 PM



Title: Problems with curl
Post by: michelemm on February 27, 2016, 03:28:21 PM
Hi all,

  this is my first post on BTC Forum.  I am experimenting with Bitcoin Core RPC, and with curl in particular, on Ubuntu.
  I start the server:  > bitcoind -rest &
  I have a Bitcoin Core wallet just for testing. I am able to call some RPC, using bitcoin-cli and curl, for instance:

curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaccounts", "params": [6] }' http://USER:PASSWD@127.0.0.1:8332/

I successfully RPC-ed the "walletpassphrase"

curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "walletpassphrase", "params": ["WALLETPASSWD", 60] }' http://USER:PASSWD@127.0.0.1:8332/ , getting:
{"result":null,"error":null,"id":"curltest"}

When I try to call the "sendmany" procedure, I get errors:

- if I try to transfer 0.0002 BTC to 3 addresses:
  curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendmany", "params": ["",  "{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002, \"1KigrTAFLRiZQuHEeX1TwfgzvijtvxU4WA\":0.0002}", 6, "testing"] }'  http://USER:PASSWD@127.0.0.1:8332/ ,  I get:
{"result":null,"error":{"code":-1,"message":"JSON value is not an object as expected"},"id":"curltest"}

- if I try to transfer 0.0002 BTC to 2 addresses (same call): 
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendmany", "params": ["",  "{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002}", 6, "testing"] }'  http://USER:PASSWD@127.0.0.1:8332/  ,  I get:
{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

  Can someone please help?

TIA

Michele


Title: Re: Problems with curl
Post by: Moloch on February 28, 2016, 06:45:10 PM
This is just a guess, but it looks like you are sending it an empty string as the first object in your array

Quote
"params": ["",  "{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002, \"1KigrTAFLRiZQuHEeX1TwfgzvijtvxU4WA\":0.0002}", 6, "testing"]

Have you tried it without an empty string as the first object?

Quote
"params": ["{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002, \"1KigrTAFLRiZQuHEeX1TwfgzvijtvxU4WA\":0.0002}", 6, "testing"]


Title: Re: Problems with curl
Post by: michelemm on February 29, 2016, 09:35:01 PM
This is just a guess, but it looks like you are sending it an empty string as the first object in your array

Quote
"params": ["",  "{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002, \"1KigrTAFLRiZQuHEeX1TwfgzvijtvxU4WA\":0.0002}", 6, "testing"]

Have you tried it without an empty string as the first object?

Quote
"params": ["{\"1HwLtBDtLGeHrLkGWHKfE7WgbCz5FbdWW4\":0.0002, \"1G3kKtEK356sfkKaykQvnv37GFUPR3Lns4\":0.0002, \"1KigrTAFLRiZQuHEeX1TwfgzvijtvxU4WA\":0.0002}", 6, "testing"]

Tanks for the help.
The first object of the array is the name of the sending account. The empty string means the default account.
Anyway, I dropped the object and rerun the curl command, but this time the server did not even bother to answer an error (and the transaction was not sent).
Giving the same "sendall" command (with the empty string) directly as parameter of bitcoin-cli, however, works.

I am still in trouble.

Michele