🚀 Investors Wanted! 📈

Join us in our journey to innovate blockchain technologies. Let's shape the future together.

Learn More Contact Us
logo

Tutorials

General

PHP

Python

NodeJs

Tutorial to send Polygon or ERC20 Tokens with PHP

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

  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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    
    <?php

// Replace with your values
$apikey = "YOURAPIKEY";
$contractaddress = "CONTRACTADDRESS";
$from = "SENDERADDRESS";
$to = "RECEIVERADDRESS";
$password = "PASSWORD";
$amount = 55.89;

$url = "https://api.chaingateway.io/v2/ethereum/transactions/erc20";

$data = array(
    "contractaddress" => $contractaddress,
    "from" => $from,
    "to" => $to,
    "password" => $password,
    "amount" => $amount
);

$headers = array(
    'Accept: application/json',
    'Authorization: ' . $apikey
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

echo $response;

?>

Code Modifications

Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel. 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

Upload the code above to your local or remote machine 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 ERC-20 Tokens.