1. Go to this page and download the library: Download bmilleare/drand-php 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/ */
bmilleare / drand-php example snippets
use Bmilleare\Drand\DrandClient;
$client = DrandClient::create($httpClient, $httpFactory, beaconId: 'quicknet');
$beacon = $client->latest(); // fetched AND verified
echo $beacon->round, PHP_EOL; // e.g. 29110875
echo $beacon->randomnessHex(), PHP_EOL; // 32-byte verifiable random value
use Bmilleare\Drand\DrandClient;
use Bmilleare\Drand\Http\CurlHttpClient;
use GuzzleHttp\Psr7\HttpFactory; // any PSR-17 factory
$factory = new HttpFactory();
$http = new CurlHttpClient($factory, $factory);
$client = DrandClient::create($http, $factory, beaconId: 'quicknet');
$beacon = $client->latest();
printf("round %d: %s\n", $beacon->round, $beacon->randomnessHex());
$beacon = $client->round(29110875); // verified, or throws InvalidSignatureException
if ($client->verify($beacon)) {
// signature is valid
}
$info = $client->chainInfo();
$round = $info->roundAt(time()); // current round number
$emittedAt = $info->timeOfRound($round);