Can I use curl to call getInfo from a the Bitcoin server?

2

1

I am wondering if its possible to use curl to getinfo from the bitcoin server thanks.

<?php
// init the resource
$ch = curl_init();

// set a single option...
$username = 'usernamefromconfig';
$pwd = 'passwordfromconfig';

curl_setopt_array(
    $ch, array( 
    CURLOPT_URL => "$username:$pwd@127.0.0.1:8336",
    CURLOPT_RETURNTRANSFER => true
));

$output = curl_exec($ch);
echo $output;

// free
curl_close($ch);
?>

Levon Willson

Posted 2015-11-13T20:17:26.967

Reputation: 23

Answers

3

You can use the command-line curl or any of the various JSON-RPC examples listed here.

In particular, you can use curl like this:

$ curl --user <username>:<password> --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/

For PHP, you can use this library and do:

require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');

echo "<pre>\n";
print_r($bitcoin->getinfo()); echo "\n";
echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";
echo "</pre>";

Jimmy Song

Posted 2015-11-13T20:17:26.967

Reputation: 7 067