Bitcoin Forum
November 14, 2024, 06:12:07 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: can get jsonRPCClient.php working  (Read 1674 times)
swisstraders (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
July 23, 2015, 05:09:52 AM
 #1

Hi,

I really hope someone can help me solve this problem. I just want to write some .php code using inputs received from bitcoin api calls but cannot get the JsonRPCClient.php working.

I can run a node (downloaded bitcoin) and can get bitcoin-qt working in the cmd prompt in windows 7;  so it is connecting to the outside world ok.

But I try to run some simple .php on my localhost (using xampp apache engine) and this line of code is not working :

    $bitcoin = new jsonRPCClient('https://bitcoinrpc:12345@127.0.0.1:8332/');

I get this error :

Warning:  fopen(https://...@127.0.0.1:8332/): failed to open stream: No connection could be made because the target machine actively refused it.
 in C:\xampp\htdocs\xampp\jsonRPCClient.php on line 132
Fatal error:  Uncaught exception 'Exception' with message 'Unable to connect to https://bitcoinrpc:12345@127.0.0.1:8332/' in C:\xampp\htdocs\xampp\jsonRPCClient.php:140
Stack trace:
#0 C:\xampp\htdocs\xampp\hello.php(14): jsonRPCClient->__call('getinfo', Array)
#1 C:\xampp\htdocs\xampp\hello.php(14): jsonRPCClient->getinfo()
#2 {main}
  thrown in C:\xampp\htdocs\xampp\jsonRPCClient.php on line 140

Can,t seem to resolve it.  Have tried various bitcoin.conf configurations, removed my firewall etc.

Any ideas please ?

nuno12345
Sr. Member
****
Offline Offline

Activity: 276
Merit: 284


View Profile
July 23, 2015, 02:26:14 PM
 #2

Hey,

Are you sure the credentials are correct? Usually it wont accept that password.

To make sure delete bitcoin.conf, start bitcoind from command line and it will trow an error complaining about rpc credentials not set and it will generate a password for you.
Copy paste those credentials into a new bitcoin.conf, after that add rpcport=24000 to it and it should work.

bitcoin.conf
Code:
rpcuser=bitcoinrpc
rpcpassword=A7e5RpBX73b6S6HKK7zYQSFCbsE5Fh2FUgftt8gwHvgg
rpcport=24000

test.php
Code:
<?php
include "jsonRPCClient.php";
$rpc = new jsonRPCClient("http://bitcoinrpc:A7e5RpBX73b6S6HKK7zYQSFCbsE5Fh2FUgftt8gwHvgg@127.0.0.1:24000/");

print_r($rpc->getinfo());
?>

The above should work, at least it works here.

Hope it helps
nuno12345
Sr. Member
****
Offline Offline

Activity: 276
Merit: 284


View Profile
July 23, 2015, 02:55:48 PM
 #3

That's normal, you need to have bitcoin running in order to enable RPC.
If you don't need a graphical interface use bitcoind.exe instead (usually servers/websites use this).

jsonRPCClient is just a pretty interface between bitcoin RPC and PHP.

If you don't want to download the blockchain you could use a third party like blockchain, but it's always better to run everything on your own server so you don't have to trust third parties, also if there is any error you are sure that it's something within your own server and not the external service down.

There is also another solution which is using bitcoinJS that connects directly to bitcoin blockchain, but it's a little more painful to setup than RPC.

Glad it worked Smiley
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!