Title: [SOLVED] Json-RPC PHP send array Post by: giantdragon on July 18, 2011, 09:58:35 PM I want to send multiple payments at once, so I use "sendmany", but seems I wrongly pass arrays. Tried
Code: for($i = 0; $i < sizeof($list); $i++) { Code: $bitcoin->sendmany(array('address1' => 0.001, 'address2' => 0.002)); both doesn't work. What I am doing incorrectly? Title: Re: Json-RPC PHP send array Post by: drawoc on July 18, 2011, 10:07:54 PM The first parameter is the account name - "" by default.
So, instead of: Code: $bitcoin->sendmany($params); Code: $bitcoin->sendmany("", $params); Title: Re: Json-RPC PHP send array Post by: giantdragon on July 18, 2011, 10:21:36 PM Code: $bitcoin->sendmany("", array('address1' => 0.001, 'address2' => 0.002)); Code: tried Title: Re: Json-RPC PHP send array Post by: giantdragon on July 18, 2011, 10:31:56 PM Solved. It seems type conversion bug in PHP, just need to explicitly convert amount to float type.
Code: $params[$address] = doubleval($amount); Title: Re: [SOLVED] Json-RPC PHP send array Post by: drawoc on July 18, 2011, 10:32:51 PM Glad it's working.
Title: Re: [SOLVED] Json-RPC PHP send array Post by: dooglus on July 21, 2012, 12:09:01 AM this isn't working for me... i've tried every different combination of single quote / double quote but the following just kills the json-rpc connection: What do you see if you do this: Quote $params = array(); var_dump($params); $params['1addr1'] = 1.2; $params['1addr2'] = 1.3; var_dump($params); var_dump($bitcoin->sendmany('account', $params)); The var_dump should show you what's going wrong. Maybe it's "PHP Fatal error: Uncaught exception 'Exception' with message 'Request error: {"code":-6,"message":"Account has insufficient funds"}'" or "PHP Fatal error: Uncaught exception 'Exception' with message 'Request error: {"code":-13,"message":"Error: Please enter the wallet passphrase with walletpassphrase first."}'" or some such other error. It should give you an idea of what's going wrong though. Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 12:59:48 AM no, it dies before the 3rd vardump can output anything:
Code: array(0) { just before that, the json connection is alive and well; i do a getinfo and it works, and sendtoaddress still works. i am trying this first on an older box, but this [version] => 40101 should be able to handle it, shouldn't it? also, i don't actually know a 'from' account because i'm using a wallet that's only ever been used in the GUI, so no account names. so I'm leaving that blank: Code: var_dump($bitcoin->sendmany('', $params)); Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 01:09:37 AM i found out how to output what's actually being sent through json:
Code: Array can't see anything wrong there though. Title: Re: [SOLVED] Json-RPC PHP send array Post by: dooglus on July 21, 2012, 02:06:05 AM Do you get any kind of an error message when it quits? Is there a logfile with errors in maybe?
Where did you get your copy of jsonRPCClient.php from? What's 40101 the version number of? Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 02:18:23 AM Do you get any kind of an error message when it quits? Is there a logfile with errors in maybe? Where did you get your copy of jsonRPCClient.php from? What's 40101 the version number of? 1. the php log file is just the usual... Warning: fopen(http://...@127.0.0.1:8332/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in... etc, etc. same as what's printed on the browser with full error reporting. this was in the tail of bitcoin's debug.log: Code:
are those ERROR's related to the sendmany? 2. i don't remember where my copy came from, but it's worked for every other function i've thrown at it. 3. 40101 is the bitcoin client, as returned by getinfo() Title: Re: [SOLVED] Json-RPC PHP send array Post by: dooglus on July 21, 2012, 03:13:08 AM I just built a version 4 bitcoind. I didn't let it touch my wallet, so I don't know if it would work fully, but it gets as far as complaining that the account I'm sending from has insufficient funds.
Can you try code like this and tell me what it shows? Code: $params = array(); Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 03:22:31 AM Code: Array line 137 of the rpc client is this: Code: if ($fp = fopen($this->url, 'r', false, $context)) { Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 03:25:55 AM oh one other thing (maybe this is where some people will say 'well, duh'), this isn't actually bitcoind. this is bitcoin.exe with server=1 in the config.
this seems to work fine for sendtoaddress... when i call sendtoaddress via json it works and i suddenly see the transaction come up in the GUI. Title: Re: [SOLVED] Json-RPC PHP send array Post by: dooglus on July 21, 2012, 05:10:04 AM It shouldn't matter whether you use bitcoin -server or bitcoind - they should react the same way to RPC calls.
I'm unable to reproduce having bitcoin fail like it is for you - but also I've not been able to find version 40101. I only see the following tags in the repository: $ git tag -l | grep v0.4 v0.4.0 v0.4.00rc1 v0.4.00rc2 and when I build v0.4.0: $ ./bitcoind getinfo { "version" : 40000, [...] the version string is 40000. I'm using Linux not Windows. I'd suggest updating to a recent version of bitcoin and see if that fixes the problem for you. I'm also wondering what happens if you try running bitcoind from the command line rather than using the PHP interface: Code: $ ./bitcoind sendmany '' '{"1tipznMYcN4SFijpcVXomcynKWAGnNBQ3":1}' You may find you need to omit the single quotes around the {...} in Windows - I'm not sure - try it with and without. Title: Re: [SOLVED] Json-RPC PHP send array Post by: payb.tc on July 21, 2012, 05:25:52 AM thanks for the help... i'm off this for now, but will reply again if i find out anything else (when i try a different version, etc).
Title: Re: Json-RPC PHP send array Post by: danystatic on October 14, 2013, 04:46:54 PM Solved. It seems type conversion bug in PHP, just need to explicitly convert amount to float type. Code: $params[$address] = doubleval($amount); Worked for me, using floatval() |