Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add transaction message #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
2 changes: 1 addition & 1 deletion src/TronInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down