Connecting *coin RPC-Server with PHP
Question
What we have to write to IP and port to connect ? I want to use my *coin-qt as a rpc-server.
<?php
require_once 'jsonRPCClient.php';
$coin = new jsonRPCClient('rpcuser:rpcpw123@IP:PORT/');
$json =$coin->getnewaddress();
var_dump($json);
echo "</pre>";
?>
Here is my .conf file :
listen=1
maxconnections=32
gen=1
genproclimit=-1
server=1
rpcuser=rpcuser
rpcpassword=rpcpw123
daemon=1
Solution
If you want to connect inside your box to the bitcoin client, then you have to use:
<?php
require_once 'jsonRPCClient.php';
$coin = new jsonRPCClient('rpcuser:rpcpw123@localhost:8332/');
$json =$coin->getnewaddress();
var_dump($json);
echo "</pre>";
?>
i.e: rpchost = localhost and rpcport = 8332 (default port for bitcoin). For a different altcoin, use the provided documentation.
You previously have to enable the rpcserver with these options in your conf file.
listen=1
server=1
daemon=1
rpcuser=rpcuser
rpcpassword=rpcpw123
rpcport=8332
rpcallowip=127.0.0.1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow