forked from iexbase/web3.php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonal.php
53 lines (45 loc) · 1.18 KB
/
personal.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
<?php
require('./exampleBase.php');
$personal = $web3->personal;
$newAccount = '';
echo 'Personal Create Account and Unlock Account' . PHP_EOL;
// create account
$personal->newAccount('123456', function ($err, $account) use (&$newAccount) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
$newAccount = $account;
echo 'New account: ' . $account . PHP_EOL;
});
$personal->unlockAccount($newAccount, '123456', function ($err, $unlocked) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
if ($unlocked) {
echo 'New account is unlocked!' . PHP_EOL;
} else {
echo 'New account isn\'t unlocked' . PHP_EOL;
}
});
// get balance
$web3->eth->getBalance($newAccount, function ($err, $balance) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
echo 'Balance: ' . $balance->toString() . PHP_EOL;
});
// remember to lock account after transaction
$personal->lockAccount($newAccount, function ($err, $locked) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
if ($locked) {
echo 'New account is locked!' . PHP_EOL;
} else {
echo 'New account isn\'t locked' . PHP_EOL;
}
});