personal.php 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require('./exampleBase.php');
  3. $personal = $web3->personal;
  4. $newAccount = '';
  5. echo 'Personal Create Account and Unlock Account' . PHP_EOL;
  6. // create account
  7. $personal->newAccount('123456', function ($err, $account) use (&$newAccount) {
  8. if ($err !== null) {
  9. echo 'Error: ' . $err->getMessage();
  10. return;
  11. }
  12. $newAccount = $account;
  13. echo 'New account: ' . $account . PHP_EOL;
  14. });
  15. $personal->unlockAccount($newAccount, '123456', function ($err, $unlocked) {
  16. if ($err !== null) {
  17. echo 'Error: ' . $err->getMessage();
  18. return;
  19. }
  20. if ($unlocked) {
  21. echo 'New account is unlocked!' . PHP_EOL;
  22. } else {
  23. echo 'New account isn\'t unlocked' . PHP_EOL;
  24. }
  25. });
  26. // get balance
  27. $web3->eth->getBalance($newAccount, function ($err, $balance) {
  28. if ($err !== null) {
  29. echo 'Error: ' . $err->getMessage();
  30. return;
  31. }
  32. echo 'Balance: ' . $balance->toString() . PHP_EOL;
  33. });