Bitcoin Forum
May 26, 2024, 03:41:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [solved] http error from json-rpc in php  (Read 4769 times)
kohlanta (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
March 05, 2013, 09:56:25 PM
Last edit: March 06, 2013, 08:07:02 AM by kohlanta
 #1

I am using the json-rpc php library from the bitcoin wiki (http://jsonrpcphp.org/) to send commands to my bitcoind instance.  For the most part, it works as expected, but occasionally, when I use the sendtoaddress command, it will return one of the following errors:
Code:
fopen(http://...@localhost:8334/): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
or
Code:
fopen(http://...@localhost:8334/): failed to open stream: HTTP request failed!
I noticed that the first one seems to happen only when there are insufficient funds in the wallet.  The second seems to happen at random.  When the first occurs, no coins are sent.  When the second occurs, the coins are almost always sent just as if there was no error even though it seems, based on the error, that the command never made it to bitcoind.  Occasionally though, the second error will be returned and the coins aren't sent.

This ambiguity is a problem for me.  What I would really like is for the jsonrpc client to return a meaningful error when it cannot process the request (such as insufficient funds) and to return the usual output (txid) when sendtoaddress is successfully executed.  I'm most comfortable in php, but am willing to learn other languages to achieve the same ends.  Ultimately I need to take addresses/amounts from a mysql database and construct transactions in my bitcoind server.

So, if anyone knows how to make this work in php or another language, perhaps perl or ruby or python and can walk me though it, and it works as described, 5 btc will be yours.
Anduck
Legendary
*
Offline Offline

Activity: 1511
Merit: 1072


quack


View Profile
March 05, 2013, 10:08:26 PM
Last edit: March 05, 2013, 10:21:02 PM by raitoninglass
 #2

Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.

kohlanta (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
March 06, 2013, 12:16:55 AM
 #3

Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.

Great ideas.  I'll play around with this and get back to you.
GoldenWings91
Full Member
***
Offline Offline

Activity: 141
Merit: 100


View Profile
March 06, 2013, 04:10:31 AM
 #4

I'm not sure about the second error but your first is caused when bitcoin returns an error. json-rpc can't handle errors and will throw an exception which would stop your entire script. When you try to send coins if there are insufficent funds bitcoin will return an error which will cause json to throw an exception. In this case you should include checks:
Quote
$balance = $bitcoind->getbalance(<account>);
$fee = 0.0005;

if($balance - $fee >= .00000001)
                   $bitcoind->sendto();
else echo "Insufficient Funds";

Support The Bitcoin Network By Running A Full Node
Node Stats     GPG Key-ID: 0x445DF2D8     Monetary Freedom Is A Basic Human Right
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
March 06, 2013, 04:13:56 AM
 #5

Your getting that error cause your script can't talk to your bitcoind, make sure you use the allowip, make sure you have the server=1, and rpcuser and rpcpass commands in your config file.
kohlanta (OP)
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
March 06, 2013, 08:06:28 AM
 #6

Try setting stream_context timeout to longer time, might help.

Or try cURL!

And try taking the http:// outta there.

And if it helps, here's an example on how to do it:
http://pastebin.com/YCYb0nPv

Let me know if any of these works.

curl solved all of my problems!  got the code I needed here: http://pastebin.com/vREuHVr5
where would you like the 5 btc sent?
Xenland
Legendary
*
Offline Offline

Activity: 980
Merit: 1003


I'm not just any shaman, I'm a Sha256man


View Profile
March 06, 2013, 08:07:32 AM
 #7

Perhaps my PHP BDK library might help http://bitcoindevkit.com
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!