Skip to content

This is an implementation of the TRON protocol in PHP using GRPC.

License

Notifications You must be signed in to change notification settings

elaheh4/tron-php-wallet-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP TRON Wallet API

This is an implementation of the TRON protocol in PHP using GRPC.

Documentation

If new to protocol buffers or GRPC start with the following documentation:

  1. Google Protocol Buffers documentation
  2. GRPC PHP documentation

Examples

List witnesses
$wallet = new \Protocol\WalletClient('47.91.216.69:50051', [
   'credentials' => Grpc\ChannelCredentials::createInsecure()
]);

$emptyMessage = new \Protocol\EmptyMessage();

/* @var \Protocol\WitnessList $witnesses */
list($witnesses, $options) = $wallet->ListWitnesses($emptyMessage)->wait();

$base58 = new Tuupola\Base58;

/* @var \Protocol\Witness $witness */
foreach ($witnesses->getWitnesses() as $witness) {
    var_dump($base58->encode($witness->getAddress()));
}
Scan the blockchain
$wallet = new \Protocol\WalletClient('47.91.216.69:50051', [
    'credentials' => Grpc\ChannelCredentials::createInsecure()
]);

$n = 15523;
do {
    $numberMessage = new \Protocol\NumberMessage();
    $numberMessage->setNum($n--);
    list($block, $meta) = $wallet->GetBlockByNum($numberMessage)->wait();
    /* @var \Protocol\Block $block */
    $transactions = $block->getTransactions();
} while(!$transactions->count());

var_dump(sprintf('block #%d seems to have %d transactions!', $n, $transactions->count()));

Development

To update PHP files according to the TRON protocol install protoc and run

sudo bash ./genphp.sh

Issues

  • Encoding and crypto utilities
  • Unit tests
  • Proper namespacing of protocol and metadata classes e.g. Tron\Protocol\Account instead of Protocol\Account
  • Add proper @return tags and type hinting (this is a protoc issue? docblocks could be improved to remove the need for inline typehinting)

About

This is an implementation of the TRON protocol in PHP using GRPC.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.2%
  • Shell 0.8%