1. Go to this page and download the library: Download logicalsteps/async library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
logicalsteps / async example snippets
eb3\Web3; //installed with `composer eb3 = new Web3('http://localhost:8545');
$eth = $web3->eth;
$eth->accounts(function ($error, $result) use ($eth, $accountNumber) {
if ($error) {
return;
}
$accounts = $result;
$eth->getBalance($accounts[$accountNumber], function ($error, $result) {
if ($error) {
return;
}
var_export((int)$result->value);
});
});
}
balance(0);
function balance($accountNumber)
{
$web3 = new Web3('http://localhost:8545');
$eth = $web3->eth;
$accounts = $eth->accounts();
$balance = $eth->getBalance($accounts[$accountNumber]);
return (int)$balance->value;
}
var_export(balance(0));
use LogicalSteps\Async\Async;
use Web3\Web3;
function balance($accountNumber)
{
$web3 = new Web3('http://localhost:8545');
$eth = $web3->eth;
$accounts = yield [$eth, 'accounts'];
$balance = yield [$eth, 'getBalance', $accounts[$accountNumber]];
$value = (int)$balance->value;
return $value;
}
Async::await(balance(0))->then('var_export');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.