Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: altoid on April 25, 2011, 02:17:14 AM



Title: help with Bitcoin development in php (variable parameters)
Post by: altoid on April 25, 2011, 02:17:14 AM
Hi all, I have run into some trouble using the bitcoin api with php.  When I issue a command like:

$bitcoin->sendfrom($userid, $receiving_address, $amount);

I get an error like:

fopen(http://...@localhost:8332/): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

But when I hard code in the parameters:

$bitcoin->sendfrom("1", "1LDNLreKJ6GawBHPgB5yfVLBERi8g3SbQS", 10);

it works fine.

I did notice that I had to put quotes around the variables in my parameters for other functions to work.  For example:

$bitcoin->getnewaddress("$userid");

But every combination of quotes or no quotes produces the error in the sendfrom function.

Thanks in advance for any help you can give.  Let me know if you need more info too.


Title: Re: help with Bitcoin development in php (variable parameters)
Post by: nodemaster on April 25, 2011, 06:45:49 AM
I don't know the PHP API, but a 500 error from a webserver means: "Woah, something went wrong but I can't tell what". Given that the request works if you hardcode the parameters I'd guess it is more likely, that the variables you use contain values, that are not correct. Try to output them for debugging purpose before you use sendfrom(). From what I see (guessed) the data types should be:

$id                Integer  No quotes
$received_address  String   Quotes
$amount            Float    No Quotes


I hope this helps.


Title: Re: help with Bitcoin development in php (variable parameters)
Post by: genjix on April 25, 2011, 08:09:19 AM

$id                Integer  No quotes
$received_address  String   Quotes
$amount            Float    No Quotes


Your problem is that $userid needs to be a string. You can cast it using (string)$userid.


Title: Re: help with Bitcoin development in php (variable parameters)
Post by: altoid on April 25, 2011, 03:41:09 PM
Thank you sooooooooooooooo much!

The the problem was they were all strings.  I cast the $amount as a float and it worked!

$amount = (float)$amount;

Are there any weird variable type requirements I might run across in the other commands, or are they all strings floats and ints?


Title: Re: help with Bitcoin development in php (variable parameters)
Post by: Gavin Andresen on April 25, 2011, 05:50:30 PM
RE: other weird variable type requirments:
sendmany's second argument is a JSON Object, with string keys and number (float) values.  I think the equivalent in PHP is a PHP Array (indexed by string).

Several routines take boolean (http://www.php.net/manual/en/language.types.boolean.php) arguments.
All the rest are strings or numbers.