Skip to content

jeyroik/toncenter-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toncenter-php-sdk

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