Binancecoin Tutorial to Create adresses with PHP

When sending or receiving BNB or BEP-20 Tokens, you need an address which is compatible with the Binance Smart Chain Blockchain. Of course, most people are using their wallets to create valid addresses. But what if you need to create hundreds of thousands of addresses for your users? Or create deposit addresses automatically whenever one of your users wants to pay you? In this case you will need a better way of generating addresses in an automated and easy way. We have written an extensive tutorial for that. Keep on reading.

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
$password = "PASSWORD"; // Secure password for the BNB address you are creating
# -------------------------------------------------------


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

# Setup request to send json via POST. This is where all parameters should be entered.
$payload = json_encode( array("password" => $password) );
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 new generated address to the screen
echo $resultdecoded["binancecoinaddress"];
?>

				
			

Code Modifications

  1. Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel.
  2. Replace “PASSWORD” in line 4 of above code with a very secure password (at least 12 characters alphanumeric of different case). Don’t lose this password as you can’t recover it!

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

Congratulations! You should now see a new generated address which you can use to send and receive BEP-20 Tokens and BNB. 

If you want to learn how to send BEP-20 Tokens from your new generated address, check out our Tutorial about ending BEP-20 Tokens.