-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
126 lines (113 loc) · 4.52 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php error_reporting(E_ALL); ini_set(disply_errors, 1);
include "vendor/autoload.php";
include 'config.php';
use Web3\Web3;
use Web3\Contract;
use Web3\Utils;
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\HttpRequestManager;
$web3 = new Web3(new HttpProvider(new HttpRequestManager('https://ropsten.infura.io/R4ZOS5AoF9gJMfGMuqJm',5)));
$web3->clientVersion(function ($err, $version) {
if ($err !== null) {
// do something
echo $err->getMessage();
return;
}
if (isset($version)) {
//echo 'Client version: ' . $version;
}
});
$eth = $web3->eth;
//echo 'Eth Get Account and Balance' . PHP_EOL;
$web3->eth->accounts(function ($err, $accounts) use ($eth) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
foreach ($accounts as $account) {
echo 'Account: ' . $account . PHP_EOL;
$eth->getBalance($account, function ($err, $balance) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
echo 'Balance: ' . $balance . PHP_EOL;
});
}
});
$contract = new Contract($web3->provider, CONTRACT_ABI);
// get function data
$userAccountAddress = '0x90C17d5D39299419983A5f5332072442Fb6e04D6';
$functionName = 'getPrice';
$params = array ('addr',$userAccountAddress);
$functionData = $contract->at(CONTRACT_ADDRESS)->getData($functionName);
//$ether = toEther($functionData, 'ether');
list($bnq, $bnr) = Utils::toEther('1', 'kether');
//echo $bnq->toString(); // 1000
// echo jsonMethodToString($functionData);
print_r($functionData);
exit;
// get balance
$eth->getBalance($userAccountAddress, function ($err, $balance) use($userAccountAddress) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
echo $userAccountAddress.' Balance: '.$balance.PHP_EOL;
});
exit;
$web3->eth->accounts(function ($err, $accounts) use ($contract, $testBytecode) {
if ($err === null) {
if (isset($accounts)) {
$accounts = $accounts;
print_r($accounts);
} else {
throw new RuntimeException('Please ensure you have access to web3 json rpc provider.');
}
// $fromAccount = $accounts[0];
// $toAccount = $accounts[1];
// $contract->bytecode($testBytecode)->new(1000000, 'Game Token', 1, 'GT', [
// 'from' => $fromAccount,
// 'gas' => '0x200b20'
// ], function ($err, $result) use ($contract, $fromAccount, $toAccount) {
// if ($err !== null) {
// throw $err;
// }
// if ($result) {
// echo "\nTransaction has made:) id: " . $result . "\n";
// }
// $transactionId = $result;
// $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($contract, $fromAccount, $toAccount) {
// if ($err !== null) {
// throw $err;
// }
// if ($transaction) {
// $contractAddress = $transaction->contractAddress;
// echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
// $contract->at($contractAddress)->send('transfer', $toAccount, 16, [
// 'from' => $fromAccount,
// 'gas' => '0x200b20'
// ], function ($err, $result) use ($contract, $fromAccount, $toAccount) {
// if ($err !== null) {
// throw $err;
// }
// if ($result) {
// echo "\nTransaction has made:) id: " . $result . "\n";
// }
// $transactionId = $result;
// $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($fromAccount, $toAccount) {
// if ($err !== null) {
// throw $err;
// }
// if ($transaction) {
// echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\nTransaction dump:\n";
// var_dump($transaction);
// }
// });
// });
// }
// });
// });
}
});
?>