1. Go to this page and download the library: Download tigusigalpa/whale-alert-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/ */
tigusigalpa / whale-alert-php example snippets
use Tigusigalpa\WhaleAlert\Config;
use Tigusigalpa\WhaleAlert\WhaleAlertClient;
// Create a config object. apiKey can be empty for the public /status endpoint,
// but authenticated endpoints st of blockchains Whale Alert supports.
$chains = $client->getSupportedBlockchains();
foreach ($chains as $chain) {
echo $chain->getName() . ': ' . implode(', ', $chain->getSymbols()) . "\n";
}
// Authenticated endpoint — " tx {$tx->getHash()}: fee={$tx->getFee()} {$tx->getFeeSymbol()}\n";
}
use Tigusigalpa\WhaleAlert\WebSocket\Client;
use Tigusigalpa\WhaleAlert\WebSocket\AlertSubscription;
use Tigusigalpa\WhaleAlert\WebSocket\EventType;
$wsUrl = sprintf('wss://leviathan.whale-alert.io/ws?api_key=%s', getenv('WHALE_ALERT_API_KEY'));
// maxReconnects is the third constructor argument. We use a named argument
// so the default connection timeout (30 seconds) is left in place.
$client = new Client($wsUrl, maxReconnects: 5, pingInterval: 30);
// Called for every decoded message.
$client->onMessage(function ($message) {
if ($message->type === EventType::Alert && $message->alert !== null) {
echo "[ALERT] {$message->alert['blockchain']}: {$message->alert['text']}\n";
}
});
// Called when a non-fatal error happens, such as a temporary disconnect.
$client->onError(function (\Throwable $e) {
fwrite(STDERR, "[ERROR] {$e->getMessage()}\n");
});
$client->connect();
// Subscribe to Ethereum whale alerts worth at least $500,000.
$client->subscribeAlerts(new AlertSubscription(
id: 'my-sub',
blockchains: ['ethereum'],
minValueUsd: 500000,
));
// listen() blocks until the connection closes.
$client->listen();
use Tigusigalpa\WhaleAlert\Exceptions\UnauthorizedException;
use Tigusigalpa\WhaleAlert\Exceptions\RateLimitException;
use Tigusigalpa\WhaleAlert\Exceptions\ApiException;
try {
$status = $client->getBlockchainStatus('ethereum');
} catch (UnauthorizedException $e) {
// The API key is missing or invalid. Check WHALE_ALERT_API_KEY.
} catch (RateLimitException $e) {
// You are sending too many requests. Back off and try $e->getRetryAfter().
} catch (ApiException $e) {
// Any other API error. Inspect $e->getStatusCode() and $e->getMessage().
}
$page = $client->listTransactions('ethereum', [
'start_height' => $status->getStartHeight(),
'limit' => 100,
]);
foreach ($page->getTransactions() as $tx) {
echo $tx->getHash() . "\n";
}
// Fetch the next page. The URL is validated against the configured base origin.
if ($page->hasNext()) {
$nextPage = $client->listTransactionsNext($page->getNext());
// process $nextPage...
}