jeyroik/toncenter-php-sdk

There is no license information available for the latest version (0.1.2) of this package.

PHP SDK for toncenter.com

0.1.2 2022-05-20 11:16 UTC

This package is auto-updated.

Last update: 2024-10-20 16:39:51 UTC


README

PHP SDK for toncenter

SDK allow to work with https://toncenter.com/api/v2/

tests codecov.io PHPStan Enabled Latest Stable Version Total Downloads Dependents

usage

Set your token (there is rps limit 1 without token)

toncenter-php-sdk$ export TONC__TOKEN=<your token>

You can get your token in the @tonapibot to get access with higher limits.

Working with address

$address = new Address([Address::FIELD__HASH => 'EQA6VbfxOrYGXvQw-VEpqeFKD1YDtX7JkQmENXOTV93Am0Yr']);
$address->loadInformation();

echo $address->getBalance(); // 15684203405
echo $address->getBalanceAsToncoins(); // 15,684203405

echo $address->getLastTransation()->getHash();

Working with transactions

$repo = new TransactionRepository();
$transaction = $repo->one(
    'EQA6VbfxOrYGXvQw-VEpqeFKD1YDtX7JkQmENXOTV93Am0yr', // by which address need to search transactions
    [
        ITransaction::FIELD__IN_MESSAGE => [
            ITransactionInMessage::FIELD__SOURCE => ['=', 'EQCtiv7PrMJImWiF2L5oJCgPnzp-VML2CAt5cbn1VsKAxLiE'],
            ITransactionInMessage::FIELD__VALUE => ['>', '9600000000'], //9.6 toncoins
            ITransactionInMessage::FIELD__MESSAGE_DATA => [
                ITransactionMessageData::FIELD__TEXT => ['like', 'ZWZ']
            ]
        ],
        ITransaction::FIELD__FEE => ['in', [1192940]]
    ]
);

echo $transaction->getId()->getHash() . PHP_EOL;

$transactions = $repo->all(
    'EQA6VbfxOrYGXvQw-VEpqeFKD1YDtX7JkQmENXOTV93Am0yr',
    [
        ITransaction::FIELD__IN_MESSAGE => [
            ITransactionInMessage::FIELD__SOURCE => ['=', 'EQCtiv7PrMJImWiF2L5oJCgPnzp-VML2CAt5cbn1VsKAxLiE'],
        ]
    ]
);

foreach($transactions as $transaction) {
    echo $transaction->getId()->getHash() . PHP_EOL;
}

Enabled conditions

  • = equal
  • != not equal
  • > greater
  • >= greater or equal
  • < lower
  • <= lower or equal
  • in equal to one among a given list
  • nin not equal to none of all given list
  • like contains
  • nlike not contains