1. Go to this page and download the library: Download radianceteam/ton-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/ */
radianceteam / ton-client-php example snippets
use TON\TonClient;
$client = new TonClient();
$result = $client->client()->version();
echo "TON SDK Version: {$result->getVersion()}";
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use TON\Client\ClientConfig;
use TON\Client\NetworkConfig;
use TON\TonClientBuilder;
$client = TonClientBuilder::create()
->withConfig((new ClientConfig())
->setNetwork((new NetworkConfig())
->setServerAddress(getenv('TON_NETWORK_ADDRESS'))))
->withLogger((new Logger("demo"))
->pushHandler(new StreamHandler('demo.log', Logger::DEBUG)))
->build();
use TON\TonClient;
use TON\Net\ParamsOfWaitForCollection;
$client = new TonClient();
$promise = $client->net()->async()->waitForCollectionAsync(
(new ParamsOfWaitForCollection())
->setCollection("transactions")
->setFilter(["now" => ["gt" => time()]])
->setResult("id now"));
echo "Awaiting for new transactions...";
$result = $promise->await();
use TON\Abi\CallSet;
use TON\Abi\Abi_Contract;
use TON\Abi\DeploySet;
use TON\Abi\Signer_Keys;
use TON\Abi\ParamsOfEncodeMessage;
use TON\Client\ClientConfig;
use TON\Client\NetworkConfig;
use TON\Net\ParamsOfSubscribeCollection;
use TON\TestClient;
use TON\TonClientBuilder;
$client = TonClientBuilder::create()
->withConfig((new ClientConfig())
->setNetwork((new NetworkConfig())
->setServerAddress(getenv('TON_NETWORK_ADDRESS'))))
->build();
$keys = $client->crypto()->generateRandomSignKeys();
$msg = $client->abi()->encodeMessage((new ParamsOfEncodeMessage())
->setAbi((new Abi_Contract())
->setValue(TestClient::load_abi('Hello')))
->setDeploySet((new DeploySet())
->setTvc(TestClient::load_tvc('Hello')))
->setSigner((new Signer_Keys())->setKeys($keys))
->setCallSet((new CallSet())
->setFunctionName("constructor")));
$subscribePromise = $client->net()->async()
->subscribeCollectionAsync((new ParamsOfSubscribeCollection())
->setCollection("transactions")
->setFilter([
"account_addr" => ["eq" => $msg->getAddress()],
"status" => ["eq" => 3] // Finalized
])
->setResult("id account_addr"));
// Wait for the very first event, then unsubscribe
$handle = $subscribePromise->await();
foreach ($subscribePromise->getEvents() as $event) {
var_dump($event);
$client->net()->unsubscribe($handle);
}