PHP code example of tigusigalpa / tokenterminal-php

1. Go to this page and download the library: Download tigusigalpa/tokenterminal-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 / tokenterminal-php example snippets


use Tigusigalpa\TokenTerminal\TokenTerminalClient;

$client = TokenTerminalClient::make('your-api-key');

$result = $client->projects()->all();
foreach ($result->data() as $project) {
    echo $project['name'] . ' (id: ' . $project['project_id'] . ")\n";
}

$client = TokenTerminalClient::fromEnv();

$config = new TokenTerminalConfig(
    apiKey: 'your-key',
    baseUrl: 'https://api.tokenterminal.com',
    timeout: 30,
    retryAttempts: 3,
    retryDelay: 1,
);

// Nothing is mutated; you always get a new instance back
$config = $config->withRetry(5, 2);
$config = $config->withRetryPOST(true);

$client = new TokenTerminalClient($config);

use Tigusigalpa\TokenTerminal\Exceptions\UnauthorizedException;
use Tigusigalpa\TokenTerminal\Exceptions\RateLimitException;
use Tigusigalpa\TokenTerminal\Exceptions\NotFoundException;
use Tigusigalpa\TokenTerminal\Exceptions\ApiException;

try {
    $result = $client->projects()->all();
} catch (UnauthorizedException $e) {
    echo "Invalid API key\n";
} catch (RateLimitException $e) {
    printf("Rate limited. Retry-After: %s\n", $e->getRetryAfter());
} catch (NotFoundException $e) {
    echo "Not found\n";
} catch (ApiException $e) {
    printf("API error %d: %s\n", $e->getStatusCode(), $e->getMessage());
}

$result = $client->projects()->historicalMetrics('uniswap', new HistoricalMetricsRequest(
    metricIds: ['fees', 'invalid-metric'],
));

foreach ($result->errors() as $error) {
    printf("Partial error: %s %s=%s\n", $error->getCode(), $error->getField(), $error->getValue());
}

use Tigusigalpa\TokenTerminal\Laravel\Facades\TokenTerminal;

$projects = TokenTerminal::projects()->all();
bash
composer 
bash
php artisan vendor:publish --tag=tokenterminal-config