Bitcoin Forum
April 26, 2024, 06:36:34 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: help with Bitcoin development in php (variable parameters)  (Read 5963 times)
altoid (OP)
Jr. Member
*
Offline Offline

Activity: 48
Merit: 9


View Profile
April 25, 2011, 02:17:14 AM
 #1

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.
1714113394
Hero Member
*
Offline Offline

Posts: 1714113394

View Profile Personal Message (Offline)

Ignore
1714113394
Reply with quote  #2

1714113394
Report to moderator
1714113394
Hero Member
*
Offline Offline

Posts: 1714113394

View Profile Personal Message (Offline)

Ignore
1714113394
Reply with quote  #2

1714113394
Report to moderator
1714113394
Hero Member
*
Offline Offline

Posts: 1714113394

View Profile Personal Message (Offline)

Ignore
1714113394
Reply with quote  #2

1714113394
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
nodemaster
Full Member
***
Offline Offline

Activity: 176
Merit: 100



View Profile WWW
April 25, 2011, 06:45:49 AM
 #2

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.
genjix
Legendary
*
Offline Offline

Activity: 1232
Merit: 1072


View Profile
April 25, 2011, 08:09:19 AM
 #3


$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.
altoid (OP)
Jr. Member
*
Offline Offline

Activity: 48
Merit: 9


View Profile
April 25, 2011, 03:41:09 PM
 #4

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?
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652
Merit: 2216


Chief Scientist


View Profile WWW
April 25, 2011, 05:50:30 PM
 #5

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 arguments.
All the rest are strings or numbers.


How often do you get the chance to work on a potentially world-changing project?
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!