Skip to content

Commit

Permalink
added sendTokenTransaction and fix getTokenBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Jul 23, 2019
1 parent 4a80d74 commit b5d0503
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ public function getTokenBalance(string $address, int $tokenId, bool $fromTron =
{
$account = $this->getAccount($address);

if(isset($account['assetV2']) and !empty($account['assetV2']) ) {
if(isset($account['assetV2']) and !empty($account['assetV2']) )
{
$value = array_filter($account['assetV2'], function($item) use ($tokenId) {
return $item['key'] == $tokenId;
});
Expand Down Expand Up @@ -640,6 +641,35 @@ public function sendTransaction(string $to, float $amount, string $message= null
return array_merge($response, $signedTransaction);
}

/**
* Send token transaction to Blockchain
*
* @param string $to
* @param float $amount
* @param int $tokenID
* @param string $from
*
* @return array
* @throws TronException
*/
public function sendTokenTransaction(string $to, float $amount, int $tokenID = null, string $from = null): array
{
if (is_null($from)) {
$from = $this->address['hex'];
}

$transaction = $this->transactionBuilder->sendToken($to, $this->toTron($amount), (string)$tokenID, $from);
if($this->isSignServer == true) {
$signedTransaction = $this->signTransactionForServer($transaction);
} else {
$signedTransaction = $this->signTransaction($transaction);
}

$response = $this->sendRawTransaction($signedTransaction);

return array_merge($response, $signedTransaction);
}

/**
* Sign the transaction, the api has the risk of leaking the private key,
* please make sure to call the api in a secure environment
Expand Down

0 comments on commit b5d0503

Please sign in to comment.