Tutorial

Subscribe to Token deposits of an ethereum address

Let's subscribe to Token deposits of an ethereum address

  1. You need basic knowledge of how to code with PHP (or know someone who can), you can also learn it at Codecademy.
  2. Create a Tokengateway.io account (if you don't have one already).
  3. Install the PHP 7 modules JSON and CURL. If you are on a Linux Debian/Ubuntu machine, you can use the following commands:
    apt-get install php7-curl
    apt-get install php7-json
    Now restart Apache with:
    service apache2 restart
  4. Create a folder with a secure name on your web server. For example B5tN-KtfOTf37 (Please use something own).
  5. Create a file named ipnreceiver.php with the following content (or download it here):
    <?php $request = file_get_contents('php://input'); $request = json_decode($request, true); file_put_contents('ipnlog.txt', "id: " . $request['id'] . " type:" . $request['type'] . " ethereumaddress: " . $request['ethereumaddress'] . " contractaddress: " . $request['contractaddress'] . "amount: " . $request['amount'] . "\r\n", FILE_APPEND); ?>
  6. Upload the created PHP script to the created folder on your web server.
  7. Create an ipnlog.txt file and upload it to the same folder and give the file write permissions. The script above 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, ...).
  8. Now create a file named createsubscription.php with the following content (or download it here):
    <?php
    # ----- REPLACE THE VARIABLES BELOW WITH YOUR DATA -----
    $apikey = "YOURAPIKEY";
    $ethereumaddress = "ETHEREUMADDRESS"; // Ethereum address you want the balance of
    $contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
    $url = "https://yourdomain.com/B5tN-KtfOTf37/ipnreceiver.php"; // URL to the previously uploaded ipnreceiver.php file # -------------------------------------------------------


    # Define function endpoint
    $ch = curl_init("https://eu.api.
    tokengateway.io/subscribeAddress");

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

    # 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 to see if it succeeded
    echo $resultdecoded['ok'];
    ?>
  9. Replace YOURAPIKEY in the above code with the API Key in your Account panel.
  10. Replace the other variables in the upper section of the code above with your data
  11. Upload the created PHP script to your web server
  12. 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.php
  13. After a few seconds, the script will return a status showing if the request was successful.
  14. Congratulations! You just created an address subscription and will receive notifications on future deposits to the provided url.
  15. If you want to create an ethereum address you can use to send Ethereum or Tokens from, check out this tutorial.