PHP code example of amashukov / toncenter-client-php
1. Go to this page and download the library: Download amashukov/toncenter-client-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/ */
amashukov / toncenter-client-php example snippets
use Amashukov\HttpClient\CurlClient;
use Amashukov\HttpClient\Middleware\HeaderInjectionMiddleware;
use Amashukov\HttpClient\Middleware\RetryMiddleware;
use Amashukov\HttpClient\Pipeline;
use Amashukov\Toncenter\ToncenterClient;
use Nyholm\Psr7\Factory\Psr17Factory;
$psr17 = new Psr17Factory();
$http = new Pipeline(
new CurlClient($psr17, $psr17, timeoutSeconds: 60),
[
// X-Api-Key lifts the rate limit from 1 RPS to 10 RPS (optional).
new HeaderInjectionMiddleware(['X-Api-Key' => $apiKey]),
// Toncenter emits transient 542 ("no workers available") + 429; retry those.
new RetryMiddleware(maxAttempts: 3, retryStatusCodes: [429, 500, 502, 503, 504, 542]),
],
);
$client = new ToncenterClient($http, $psr17, $psr17);
$info = $client->getMasterchainInfo(); // TonMasterchainInfo
$balance = $client->getBalance('EQ...'); // decimal-string nano-TON
$account = $client->getAddressInformation('EQ...');
if ($account->isActive()) {
// ...
}
use Amashukov\Toncenter\ToncenterWalletRpc;
$rpc = new ToncenterWalletRpc($client);
$seqno = $rpc->getSeqno($walletRawAddress); // 0 if the wallet is not yet deployed
$rpc->sendBoc($signedTransferBocBase64);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.