Simple PHP Script

in cn •  7 years ago  (edited)


<?
class Steemd
{
   private $ch;
   function __construct(){
     $this->ch = curl_init();
     curl_setopt($this->ch, CURLOPT_URL, 'https://steemd.steemit.com');
     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
   }

   function __destruct() {
     curl_close($this->ch);
   }

   private function json_rpc_body($method, $params){
       $request = array(
           "jsonrpc" => "2.0",
           "method" => $method,
           "params" => $params,
           "id" => 0
           );
       return json_encode($request);
   }

   public function exec($method, $params = array()) {
       $data = $this->json_rpc_body($method, $params);
       curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
       $response = curl_exec($this->ch);
       $response = json_decode($response, true);
       if (array_key_exists('error', $response)) {
         var_dump($response['error']);
         die();
       }
       return $response['result'];
   }

   public function get_account($account){
       $result = $this->exec('get_accounts', [[$account]]);
       return $result;
   }
}

$steemd = new Steemd;
echo('<pre>');
print_r($steemd->exec(get_chain_properties,[]));
print_r($steemd->get_account('oflyhigh'));
echo('</pre>');

//unset($steemd);
?>
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://steemit.com/cn/@oflyhigh/php-steem-using-php-to-query-the-steem-blockchain

Hi. I am a volunteer bot for @resteembot that upvoted you.
Your post was chosen at random, as part of the advertisment campaign for @resteembot.
@resteembot is meant to help minnows get noticed by re-steeming their posts


To use the bot, one must follow it for at least 3 hours, and then make a transaction where the memo is the url of the post.
If you want to learn more - read the introduction post of @resteembot.
If you want help spread the word - read the advertisment program post.


Steem ON!