🚀 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 NodeJs

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.

Prerequisites

  1. Basic knowledge of Nodejs
  2. Account at Chaingateway.io
  3. A local or remote machine with NodeJs and installed axios module

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
    
    /*
    * Replace with your Values
    */
    var apikey = "YOURAPIKEY"; // API Key in your account panel
    var contractaddress = "CONTRACTADDRESS"; // Smart contract address of the Token
    var from = "SENDERADDRESS"; // Polygon address you want to send from (must have been created with Chaingateway.io)
    var to = "RECEIVERADDRESS"; // Receiving polygon address
    var password = "PASSWORD"; // Password of the polygon address (which you specified when you created the address)
    var amount = 55.89; // Amount of Tokens to send

    var axios = require('axios');

    var data = JSON.stringify({
        "contractaddress": contractaddress,
        "from": from,
        "to": to,
        "password": password,
        "amount": amount
        });

    var config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'https://api.chaingateway.io/v2/polygon/transactions/erc20',
    headers: { 
        'Accept': 'application/json',
        'Authorization': apikey
    },
    data : data
    };

    axios(config)
    .then(function (response) {
    console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
    console.log(error);
    });

Code Modifications

Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel. Replace “CONTRACTADDRESS” in line 4 with the smart contract address of the Token. Replace “SENDERADDRESS” in line 5 with the polygon address you want to send from. Replace “RECEIVERADDRESS” in line 6 with the receiving polygon address Replace “PASSWORD” in line 7 with your password of the polygon address, which you specified when you created the address. 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 Etherscan.

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