diff --git a/examples/accounts2.php b/examples/accounts2.php new file mode 100644 index 00000000..671abab9 --- /dev/null +++ b/examples/accounts2.php @@ -0,0 +1,36 @@ +eth; + +echo 'Eth Get Account and Balance' . PHP_EOL; +$promises = []; +$promises[] = $eth->accounts(function ($err, $accounts) use ($eth) { + if ($err !== null) { + echo 'Error: ' . $err->getMessage(); + return; + } + + foreach ($accounts as $account) { + echo 'Account: ' . $account . PHP_EOL; + + $promises[] = $eth->getBalance($account, function ($err, $balance) { + if ($err !== null) { + echo 'Error: ' . $err->getMessage(); + return; + } + echo 'Balance: ' . $balance . PHP_EOL; + }); + } + + // wait all promises + Async\await(Promise\all($promises)); + echo 'close connection...' . PHP_EOL; + $eth->provider->close(); +});