diff --git a/src/TransactionBuilder.php b/src/TransactionBuilder.php index f940de5..2f70006 100644 --- a/src/TransactionBuilder.php +++ b/src/TransactionBuilder.php @@ -36,7 +36,7 @@ public function __construct(Tron $tron) * @return array * @throws TronException */ - public function sendTrx($to, $amount, string $from = null) + public function sendTrx($to, $amount, string $from = null, string $message = null) { if ($amount < 0) { throw new TronException('Invalid amount provided'); @@ -53,11 +53,17 @@ public function sendTrx($to, $amount, string $from = null) throw new TronException('Cannot transfer TRX to the same account'); } - $response = $this->tron->getManager()->request('wallet/createtransaction', [ + $params = [ 'to_address' => $to, 'owner_address' => $from, 'amount' => $this->tron->toTron($amount), - ]); + ]; + + if(!is_null($message)) { + $params['extra_data'] = $this->tron->stringUtf8toHex($message); + } + + $response = $this->tron->getManager()->request('wallet/createtransaction', $params); return $response; } diff --git a/src/Tron.php b/src/Tron.php index 9d51343..7a2ac9d 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -675,20 +675,20 @@ public function getTransactionCount(): int * Send transaction to Blockchain * * @param string $to - * @param float $amount + * @param string $amount * @param string|null $message * @param string $from * * @return array * @throws TronException */ - public function sendTransaction(string $to, float $amount, string $message= null, string $from = null): array + public function sendTransaction(string $to, string $amount, string $message= null, string $from = null): array { if (is_null($from)) { $from = $this->address['hex']; } - $transaction = $this->transactionBuilder->sendTrx($to, $amount, $from); + $transaction = $this->transactionBuilder->sendTrx($to, $amount, $from, $message); $signedTransaction = $this->signTransaction($transaction, $message); diff --git a/src/TronInterface.php b/src/TronInterface.php index 32220e1..a1f0325 100644 --- a/src/TronInterface.php +++ b/src/TronInterface.php @@ -60,7 +60,7 @@ public function getTransactionCount(); * @return array * @throws TronException */ - public function sendTransaction(string $to, float $amount, string $from = null); + public function sendTransaction(string $to, string $amount, string $from = null); /** * Modify account name