forked from kesar/ethereum-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e72d591
Showing
21 changed files
with
830 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"require": { | ||
"graze/guzzle-jsonrpc": "^3.2" | ||
}, | ||
"autoload": { | ||
"psr-4": {"": "src/"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.