<?php
require_once('jsonRPCClient.php');
/** SIMPLE BITCOIN JSON RPC PHP**/
$btc_connect = array("user" => "youusername", // RPC Username
"pass" => "yourpassword", // RPC Password
"host" => "127.0.0.1", // RPC Hostname/IP
"port" => 8321); // RPC Port
define('SENDTOADDRESS', '1PasoXBiRaitEvnWHjjkjReVFkQeNt2KxE');
//create an array with connection settings
$mybtc = new jsonRPCClient("http://{$btc_connect['user']}:{$btc_connect['pass']}@{$btc_connect['host']}:{$btc_connect['port']}");
$balance_1 = $mybtc->getbalance('*', 0);
$balance_2 = $mybtc->getbalance('*', 1);
$diff = $balance_1 - $balance_2;
echo '_______________________________________________'."\n";
echo 'Php Simple JSON RPC PHP Example by BitcoinPlaza'."\n";
echo '_______________________________________________'."\n";
echo 'Total available Balance: '.$balance_1."\n";
echo 'Confirmed Balance: '.$balance_2."\n";
echo 'Waiting for confirmation: '.$diff."\n";
echo '_______________________________________________'."\n";
echo 'This simple script is for testing purpose only '."\n";
echo 'it check you balance and print it out '."\n";
echo 'then send 0,1 Bitcoin to me address for donation'."\n";
echo '_______________________________________________'."\n";
echo "ARE YOU SURE ? Type 'yes' to continue or any key to exit: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes'){
echo "EXIT! BYE\n";
die;
}
echo "\n";
echo "Thank you, for your support...\n";
try{
$bet = 0.1;
$mybtc->sendtoaddress(SENDTOADDRESS, (float) $bet); // send bet
catch(Exception $e)
{
echo "Have: " . $mybtc->getbalance('*', 1) . " Needed: " . $bet . "\n";
die("not enought money?\n");
}
}
?>