forked from mrsantran/ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
83 lines (74 loc) · 3.14 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use Ethereum\EthereumClient;
include 'vendor/autoload.php';
$myAddress = new \Ethereum\Types\Address('0x2e94757df1267f244f4b9ef049416c6794a60552');
$otherAddress = new \Ethereum\Types\Address('0x22c5071a37432ac845a57c4a69339d161b6baa22');
$client = new EthereumClient('http://localhost:8545');
$ether = new \Ethereum\Types\Ether(1);
$ether2 = new \Ethereum\Types\Ether(1);
echo $ether->toWei()->amount() - $ether2->toWei()->amount();
/*
$lastBlock = $client->eth()->blockNumber();
for ($i = 0; $i <= $lastBlock; $i++) {
echo 'checking block: '.$i."\n";
$block = $client->eth()->getBlockByNumber(new \Ethereum\Types\BlockNumber($i));
if (count($block->transactions()) > 0) {
foreach ($block->transactions() as $transaction) {
echo $transaction."\n";
}
}
}
*/
//$transaction = $client->eth()->getTransactionByHash(new \Ethereum\Types\TransactionHash('0xba045379c4bae068f56ae656d8f54ad53d303588307bd272a969d7479794a61a'));
//print_r($transaction);
/*
echo 'My address: '. $client->eth()->getBalance($myAddress, new BlockNumber())->toEther()."\n";
echo 'Other address: '. $client->eth()->getBalance($otherAddress, new BlockNumber())->toEther()."\n";
echo 'Unlocking my account: '. $client->personal()->unlockAccount($myAddress, 'test', 20)."\n";
$transaction = new \Ethereum\Types\Transaction(
$myAddress,
$otherAddress,
null,
null,
null,
(new \Ethereum\Types\Ether(5))->toWei()->amount()
);
echo 'Sending transaction tx: '. $client->eth()->sendTransaction($transaction)->toString();
*/
/*
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";
*/