Bitcoin RPC PHP JSON EXAMPLE


SUBMITTED BY: Guest

DATE: Jan. 18, 2013, 11:44 a.m.

FORMAT: PHP

SIZE: 2.2 kB

HITS: 4374

  1. <?php
  2. require_once('jsonRPCClient.php');
  3. /** SIMPLE BITCOIN JSON RPC PHP**/
  4. $btc_connect = array("user" => "youusername", // RPC Username
  5. "pass" => "yourpassword", // RPC Password
  6. "host" => "127.0.0.1", // RPC Hostname/IP
  7. "port" => 8321); // RPC Port
  8. define('SENDTOADDRESS', '1PasoXBiRaitEvnWHjjkjReVFkQeNt2KxE');
  9. //create an array with connection settings
  10. $mybtc = new jsonRPCClient("http://{$btc_connect['user']}:{$btc_connect['pass']}@{$btc_connect['host']}:{$btc_connect['port']}");
  11. $balance_1 = $mybtc->getbalance('*', 0);
  12. $balance_2 = $mybtc->getbalance('*', 1);
  13. $diff = $balance_1 - $balance_2;
  14. echo '_______________________________________________'."\n";
  15. echo 'Php Simple JSON RPC PHP Example by BitcoinPlaza'."\n";
  16. echo '_______________________________________________'."\n";
  17. echo 'Total available Balance: '.$balance_1."\n";
  18. echo 'Confirmed Balance: '.$balance_2."\n";
  19. echo 'Waiting for confirmation: '.$diff."\n";
  20. echo '_______________________________________________'."\n";
  21. echo 'This simple script is for testing purpose only '."\n";
  22. echo 'it check you balance and print it out '."\n";
  23. echo 'then send 0,1 Bitcoin to me address for donation'."\n";
  24. echo '_______________________________________________'."\n";
  25. echo "ARE YOU SURE ? Type 'yes' to continue or any key to exit: ";
  26. $handle = fopen ("php://stdin","r");
  27. $line = fgets($handle);
  28. if(trim($line) != 'yes'){
  29. echo "EXIT! BYE\n";
  30. die;
  31. }
  32. echo "\n";
  33. echo "Thank you, for your support...\n";
  34. try{
  35. $bet = 0.1;
  36. $mybtc->sendtoaddress(SENDTOADDRESS, (float) $bet); // send bet
  37. catch(Exception $e)
  38. {
  39. echo "Have: " . $mybtc->getbalance('*', 1) . " Needed: " . $bet . "\n";
  40. die("not enought money?\n");
  41. }
  42. }
  43. ?>

comments powered by Disqus