Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kesar committed Nov 11, 2017
0 parents commit e72d591
Show file tree
Hide file tree
Showing 21 changed files with 830 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
vendor/
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"graze/guzzle-jsonrpc": "^3.2"
},
"autoload": {
"psr-4": {"": "src/"}
}
}
49 changes: 49 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

use EthereumPHP\EthereumClient;
use EthereumPHP\Types\BlockHash;
use EthereumPHP\Types\BlockNumber;

include 'vendor/autoload.php';

$randomAddress = new \EthereumPHP\Types\Address('0x7eff122b94897ea5b0e2a9abf47b86337fafebdc');
$randomHash = '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238';

$client = new EthereumClient('http://localhost:8545');
echo $client->net()->version()."\n";
echo $client->net()->listening()."\n";
echo $client->net()->peerCount()."\n";
echo $client->web3()->clientVersion()."\n";
echo $client->web3()->sha3('0x68656c6c6f20776f726c64')."\n";
echo $client->eth()->protocolVersion()."\n";
echo $client->eth()->syncing()."\n";
$coinbase = $client->eth()->coinbase();
if ($coinbase) {
echo $coinbase->toString()."\n";
}
echo $client->eth()->mining()."\n";
echo $client->eth()->hashRate()."\n";
echo $client->eth()->gasPrice()->toEther()."\n";
foreach ($client->eth()->accounts() as $account) {
echo $account->toString()."\n";
}
echo $client->eth()->blockNumber()."\n";
echo $client->eth()->getBalance($randomAddress, new BlockNumber())->toEther()."\n";
echo $client->eth()->getTransactionCount($randomAddress, new BlockNumber())."\n";
echo $client->eth()->getBlockTransactionCountByHash(new BlockHash($randomHash))."\n";
echo $client->eth()->getUncleCountByBlockHash(new BlockHash($randomHash))."\n";
echo $client->eth()->getUncleCountByBlockNumber(new BlockNumber())."\n";
echo $client->eth()->getCode($randomAddress, new BlockNumber())."\n";
echo $client->eth()->sign($randomAddress, '0xdeadbeaf')."\n";
foreach ($client->eth()->getCompilers() as $compiler) {
echo $compiler."\n";
}
print_r($client->eth()->compileSolidity('contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"'));

foreach ($client->personal()->listAccounts() as $account) {
echo $account->toString()."\n";
}

$account = $client->personal()->newAccount('test');
echo $account->toString()."\n";
echo $client->personal()->unlockAccount($account, 'test', 20)."\n";
53 changes: 53 additions & 0 deletions src/EthereumPHP/EthereumClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace EthereumPHP;

use EthereumPHP\Methods\Eth;
use EthereumPHP\Methods\Net;
use EthereumPHP\Methods\Personal;
use EthereumPHP\Methods\Shh;
use EthereumPHP\Methods\Web3;
use Graze\GuzzleHttp\JsonRpc\Client;

class EthereumClient
{
private $client;
private $methods = [];

public function __construct(string $url)
{
$this->client = Client::factory($url);
$this->methods = [
'net' => new Net($this->client),
'eth' => new Eth($this->client),
'shh' => new Shh($this->client),
'web3' => new Web3($this->client),
'personal' => new Personal($this->client),
];
}

public function net(): Net
{
return $this->methods['net'];
}

public function web3(): Web3
{
return $this->methods['web3'];
}

public function shh(): Shh
{
return $this->methods['shh'];
}

public function eth(): Eth
{
return $this->methods['eth'];
}

public function Personal(): Personal
{
return $this->methods['personal'];
}
}
15 changes: 15 additions & 0 deletions src/EthereumPHP/Methods/AbstractMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EthereumPHP\Methods;

use Graze\GuzzleHttp\JsonRpc\ClientInterface;

abstract class AbstractMethods
{
protected $client;

public function __construct(ClientInterface $client)
{
$this->client = $client;
}
}
Loading

0 comments on commit e72d591

Please sign in to comment.