Binancecoin tutorial to send BEP-20 Tokens with PHP

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

Prerequisites

  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

				
					
<?php
# ----- REPLACE THE VARIABLES BELOW WITH YOUR DATA -----
$apikey = "YOURAPIKEY"; // API Key in your account panel
$contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
$from = "SENDERADDRESS"; // Binancecoin address you want to send from (must have been created with Chaingateway.io)
$to = "RECEIVERADDRESS"; // Receiving Binancecoin address
$password = "PASSWORD"; // Password of the Binancecoin address (which you specified when you created the address)
$amount = "55.89"; // Amount of Tokens to send
# -------------------------------------------------------

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

# 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, "password" => $password, "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);
curl_close($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 Binancecoin address you want to send from.
  4. Replace “RECEIVERADDRESS” in line 6 with the receiving Binancecoin address
  5. Replace “PASSWORD” in line 7 with your password of the Binancecoin 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 BscScan

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

If you want to learn how to get BEP-20 token balance of an Binancecoin address, check out our Tutorial about balance of BEP-20 Tokens.