jfreak53 (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 08, 2011, 09:51:41 PM |
|
Anyone have any experience developing a perl client with bitcoin and JSON? Having a problem when sending parameters to the RPC. When sending params it comes back "500 Internal Server Error", without params RPC works fine. Have tried a bunch of way but this is how it should be, right? my $obj = { method => 'listreceivedbyaddress', params => [ 0, true ], }; Keep getting that 500 error with params, like I said without params works fine. Tried ', " and I don't know how many other combinations. Anyone else ever have this problem?
|
█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options! Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
|
|
|
2112
Legendary
Offline
Activity: 2128
Merit: 1073
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 08, 2011, 11:26:20 PM Last edit: October 09, 2011, 02:01:40 AM by 2112 |
|
Post the whole non-working but runnable code snippet. Otherwise it is hard to guess.
Edit: yeah, I'm slow. Change "true" to "JSON::true".
|
|
|
|
jfreak53 (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 09, 2011, 12:27:39 AM |
|
It's off the API page. my $obj = { method => 'listreceivedbyaddress', params => [ 0, true ], }; my $res = $client->call( $uri, $obj ); if ($res) { if ($res->is_error) { print "Error : ", $res->error_message; exit; } else { print Dumper($myres); } } else { print $client->status_line; exit; }
As stated it works without the params part just fine, but if I include the params in any form it hits the line: print $client->status_line; exit; Because it doesn't work with params for some reason, well I figure we have them in wrong some how but not sure how.
|
█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options! Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
|
|
|
mndrix
Michael Hendricks
VIP
Sr. Member
Offline
Activity: 447
Merit: 258
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 09, 2011, 01:27:17 AM |
|
Without seeing your entire program (for example, variables $client and $uri aren't defined in your snippet above), it's hard to say for sure what's going wrong. I'm suspicious of "true" in the params line since Perl has no native boolean type. In this context, you probably need $JSON::true I use Finance::Bitcoin::API for Perl programs that interact with the Bitcoin API. It works great. Here's an example: use strict; use warnings; use Finance::Bitcoin::API; use Data::Dumper;
my $uri = 'http://username:password@127.0.0.1:8332'; my $api = Finance::Bitcoin::API->new( endpoint => $uri ); my $received = $api->call( 'listreceivedbyaddress', 0, $JSON::true ); print Dumper($received);
|
|
|
|
jfreak53 (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 09, 2011, 01:35:29 AM |
|
Beautiful, that's actually what it was. Didn't really think it would matter since it was passing it to the bitcoind program and it was handling the boolean. But that worked thank you.
|
█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options! Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
|
|
|
jfreak53 (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 09, 2011, 02:19:11 PM |
|
Ok now the same problem am having with the 'sendtoaddress' command. The amount is the problem here. Bitcoind is expecting a real constant, and it's giving the same error. Have tried Data::Types and to_real, to_float and to_decimal, none seem to work. Also tried just sending the amount, for instance, this doesn't work with any of the above or alone: my $obj = { method => 'sendtoaddress', params => ["$in{address}", $in{amount}], }; But this does: my $obj = { method => 'sendtoaddress', params => ["$in{address}", 0.005], }; Any other ideas on how to convert that amount to a real in perl??
|
█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options! Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
|
|
|
jfreak53 (OP)
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
October 09, 2011, 02:58:05 PM |
|
Ok nevermind did a small trick and made it work, don't know if it's the right way but it works for future reference anyone looking. Correct way is: $amt = $in{amount} + 0.0; my $obj = { method => 'sendtoaddress', params => ["$in{address}", $amt], };
|
█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options! Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
|
|
|
ethought
Legendary
Offline
Activity: 1316
Merit: 1000
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
May 31, 2013, 02:28:56 PM |
|
Ok nevermind did a small trick and made it work, don't know if it's the right way but it works for future reference anyone looking. Correct way is: $amt = $in{amount} + 0.0; my $obj = { method => 'sendtoaddress', params => ["$in{address}", $amt], }; Thank you - just what I was looking for.
|
|
|
|
|