Add example to personal api.
This commit is contained in:
parent
4ad0cb13c3
commit
bac5cc8c31
40
examples/personal.php
Normal file
40
examples/personal.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?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;
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user