Tutorial to subscribe to TRC20 Token deposits of an Tron address
This tutorial will show you how to receive automated messages when you receive money on the selected Tron address. The only thing needed is a Tron address where the money will land and a URL where the notification will be sent.
Prerequisites
- Basic knowledge of PHP
- Account at Chaingateway.io
- A local or remote machine with PHP7 and installed modules JSON and CURL
IPN receiver
- Create a folder with a secure name on your web server. For example B5tN-KtfOTf37 (Please use something own).
- Upload the following PHP code in the new generated folder on your web server.
- Create a file named ipnlog.txt and upload it to the same folder and give the file write permissions. The script below will log all deposits to the ipnlog.txt file. You can process deposits the way you want of course (Example: Update user balances, Mark orders as paid, …).
true];
$response = json_encode($response);
echo $response;
?>
The Code
$contractaddress, "tronaddress" => $tronaddress, "url": $url) );
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);
curl_close($ch);
# Decode the received JSON string
$resultdecoded = json_decode($result, true);
# Print status of request (should be true if it worked)
echo $resultdecoded["ok"];
?>
Code Modifications
- Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel.
- Replace “ethereumaddress” in line 4 of above code with Contract address of the token you want to watch.
- Replace “contractaddress” in line 5 of above code with the tron address you want to watch.
- Replace “https://yoururl.com/ipnreceiver.php” in line 6 of above code with the URL you want to receive updates.
Final Steps
- Upload the code above to your local or remote machine
- Call the script in your browser. For example, if you upload it to the root directory of your website, you can call it by typing yourwebsite.com/createsubscription.php
- After a few seconds, the script will return a status showing if the request was successful.
Congratulations! You just created an address subscription and will receive notifications on future deposits to the provided url.
If you want to create an Tron address you can use to send TRC10 or TRC20 Tokens from, check out this tutorial about create Binancecoin adresses.