Subscribe to Token deposits of an ethereum address
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"] . " action:" . $request["action"] . " type:" . $request["type"] . " ethereumaddress:" . $request["ethereumaddress"] . " contractaddress:" . $request["contractaddress"] . "amount:" . $request["amount"] . "\r\n", FILE_APPEND);
?>
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, ...).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'];
?>