olifanton / ton
PHP library for The Open Network blockchain
Requires
- php: >=8.1
- ext-json: *
- ext-sodium: *
- olifanton/interop: ^1.1
- olifanton/mnemonic: ^1.0.2
- php-http/client-common: ^2.0
- php-http/discovery: ^1.0
- php-http/httplug: ^2.0
- psr/http-client-implementation: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0
- psr/log: ^1.0|^2.0|^3.0
- psr/simple-cache: ^3.0
Requires (Dev)
- cakephp/cache: ^5.0
- guzzlehttp/guzzle: ^7.5
- http-interop/http-factory-guzzle: ^1.2
- jetbrains/phpstorm-attributes: ^1.0
- mockery/mockery: ^1.5
- overtrue/phplint: ^9.0
- php-http/guzzle7-adapter: ^1.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- vlucas/phpdotenv: ^5.4
README
Prerequisites
- Minimum PHP 8.1;
ext-hash
;ext-sodium
required as default cryptographic implementation;- any httplug-compatible HTTP client (
php-http/client-common
), see Documentation; ext-bcmath
not required, but strongly recommended for performance reasons.
Installation
composer require olifanton/ton
Examples
See examples
directory.
Running examples
- Clone repository and install with development dependencies;
- Get own testnet API key for Toncenter from Telegram bot;
- Copy
.env.dist
to.env
; - Put API key and seed phrase variables to
.env
file; - Run examples in console.
Documentation
Toncenter transport initialization
To use the SDK via Toncenter API, an HTTP client implementation is required. For the example, Guzzle will be used. If you are using another HTTP client supplied by your framework, refer to your framework's documentation and the httplug
documentation for additional information.
- Install http components via Composer:
composer require guzzlehttp/guzzle http-interop/http-factory-guzzle php-http/guzzle7-adapter
- Setup Toncenter transport:
<?php use Http\Client\Common\HttpMethodsClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\Psr17FactoryDiscovery; use Olifanton\Ton\Transports\Toncenter\ToncenterHttpV2Client; use Olifanton\Ton\Transports\Toncenter\ClientOptions; use Olifanton\Ton\Transports\Toncenter\ToncenterTransport; $isMainnet = false; $toncenterApiKey = "..."; // Request API key from https://t.me/tontestnetapibot or https://t.me/tonapibot // HTTP client initialization $httpClient = new HttpMethodsClient( HttpClientDiscovery::find(), Psr17FactoryDiscovery::findRequestFactory(), Psr17FactoryDiscovery::findStreamFactory(), ); // Toncenter API client initialization $toncenter = new ToncenterHttpV2Client( $httpClient, new ClientOptions( $isMainnet ? "https://toncenter.com/api/v2" : "https://testnet.toncenter.com/api/v2", $toncenterApiKey, ), ); // Transport initialization $toncenterTransport = new ToncenterTransport($toncenter); // ... // Now you can use Toncenter transport as access point to blockchain $toncenterTransport->send($someBoc);
See examples/common.php
for complex Toncenter example.
SDK components
Primitives
To read description of primitives (Address, Cell, Slice, Builder, Hashmap), refer to documentation in the olifanton/interop
repository.
Framework integration
@WIP
Contributing
Please make sure to read the Olifanton contribution guide before making a pull request.
Setup environment
Prepare your environment for development.
Note that the instructions describe working on *nix systems (Linux and possibly macOS), development on Windows may be difficult and will not be covered in these instructions.
You'll need:
- Minimum PHP version: 8.1;
sodium
extension;hash
extension.
Fork repository
Make a repository fork in your GitHub account.
Clone your repository
git clone git@github.com:<YOUR_GITHUB_NAME>/ton.git cd ton
Create a feature/
(or hotfix/
) branch
git branch feature/<FEATURE_NAME> git checkout feature/<FEATURE_NAME>
Create pull request
After implementing your new feature (or hotfix) in your local branch, you should commit and push changes to your fork repository. After that you can create a pull-request.
Tests
composer run test:unit
License
MIT