Tutorial to send TRC20 Tokens with PHP

To send or receive TRC20 tokens, you need an address that is compatible with the Tron blockchain. Of course, most people use their wallets to send TRC20 tokens. But what if you need to make hundreds of thousands of transactions? In this case, you require a better way to send TRC20 tokens in an automated way. We have written a detailed tutorial for this purpose. Read more.


  1. Basic knowledge of PHP
  2. Account at Chaingateway.io
  3. A local or remote machine with PHP7 and installed modules JSON and CURL

The Code

$apikey = "YOURAPIKEY"; // API Key in your account panel
$contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
$from = "SENDERADDRESS"; // Ethereum address you want to send from (must have been created with Chaingateway.io)
$to = "RECEIVERADDRESS"; // Receiving ethereum address
$privatekey = "PRIVATEKEY"; // Private Key of the tron address (which you received when you created the address)
$amount = "55.89"; // Amount of Tokens to send
# -------------------------------------------------------

# Define function endpoint
$ch = curl_init("https://eu.trx.chaingateway.io/v1/sendTRC20");

# Setup request to send json via POST. This is where all parameters should be entered.
$payload = json_encode( array("contractaddress" => $contractaddress, "from" => $from, "to" => $to, "privatekey" => $privatekey, "amount" => $amount) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Authorization: " . $apikey));

# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

# Send request.
$result = curl_exec($ch);

# Decode the received JSON string
$resultdecoded = json_decode($result, true);

# Print the transaction id of the transaction
echo $resultdecoded["txid"];


Code Modifications

  1. Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel.
  2. Replace “CONTRACTADDRESS” in line 4 with the smart contract address of the Token.
  3. Replace “SENDERADDRESS” in line 5 with the Tron address you want to send from.
  4. Replace “RECEIVERADDRESS” in line 6 with the receiving Tron address
  5. Replace “PASSWORD” in line 7 with your password of the Tron address, which you specified when you created the address.
  6. Replace “55.89” in line 8 with the amount of Tokens you want to send.

Final Steps

  1. Upload the code above to your local or remote machine
  2. Call the script by navigating to your favorite browser and entering the URL. For example, if you upload it to the root directory of your website, you can call it by typing yourwebsite.com/name-of-the-above-code.php
  3. After a few seconds, the script will return a transaction id (which means the transaction has been sent successfully). You can lookup this transaction id for example on Tronscan

Congratulations! You just sent BEP-20 Tokens using Chaingateway.io. Wasn’t that hard, right?

If you want to learn how to get TRC20 token balance of an Tron address, check out our Tutorial about balance of TRC10 & TRC20 Tokens.