Create Token Transactions
Create Token Transactions
Section titled “Create Token Transactions”Introduction
Section titled “Introduction”In this tutorial, we will cover how to create ERC20 (Ethereum), BEP20 (Binance Smart Chain), and TRC20 (Tron) token transactions using the Chaingateway V2 API. We will provide examples in various programming languages, including Shell (cURL), PHP, Python, and JavaScript.
For obtaining an API key and learning about authorization, please refer to the Getting Started section of the ChainGateway documentation.
To make transactions from Ethereum, BSC or Polygon, your address needs to be imported to chaingateway or was created with the chaingateway api. Otherwise the authorization procedure will not work.
To create an address, refer to tutorial section
Creating ERC20 and BEP20 Transactions
Section titled “Creating ERC20 and BEP20 Transactions”When making a token transaction on Ethereum, Polygon (ERC20) or Binance Smart Chain (BEP20), you need to send a request to the Chaingateway API with the appropriate parameters.
Parameters
Section titled “Parameters”- from: The sender’s address.
- to: The recipient’s address.
- amount: The amount to send.
- contractaddress: The contract address of the token.
- password: The password used to encrypt the keystore file of the sender’s address.
Example Authorization Header
Section titled “Example Authorization Header”Replace YOUR_API_TOKEN with your actual API token.
Example Code
Section titled “Example Code”curl --request POST \ --url https://api.chaingateway.io/v2/ethereum/transactions/erc20 \ --header 'Accept: application/json' \ --header 'content-type: application/json' \ --header 'Authorization: YOUR_API_TOKEN' \ --data '{ "from": "0xYourSenderAddress", "to": "0xRecipientAddress", "amount": "100", "contractaddress": "0xTokenContractAddress", "password": "YourPassword" }'const axios = require('axios');
const url = 'https://api.chaingateway.io/v2/ethereum/transactions/erc20';const payload = { from: '0xYourSenderAddress', to: '0xRecipientAddress', amount: '100', contractaddress: '0xTokenContractAddress', password: 'YourPassword'};const headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'};
axios.post(url, payload, { headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });import requests
url = "https://api.chaingateway.io/v2/ethereum/transactions/erc20"payload = { "from": "0xYourSenderAddress", "to": "0xRecipientAddress", "amount": "100", "contractaddress": "0xTokenContractAddress", "password": "YourPassword"}headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'}
response = requests.post(url, json=payload, headers=headers)print(response.json())<?phprequire 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();$response = $client->post('https://api.chaingateway.io/v2/ethereum/transactions/erc20', [ 'headers' => [ 'Accept' => 'application/json', 'content-type' => 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ], 'json' => [ 'from' => '0xYourSenderAddress', 'to' => '0xRecipientAddress', 'amount' => '100', 'contractaddress' => '0xTokenContractAddress', 'password' => 'YourPassword' ]]);
echo $response->getBody();?>The code should return this response:
{ "status": 201, "ok": true, "message": "Succesfully created transaction", "data": { "txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27" }}Creating TRC20 Transactions
Section titled “Creating TRC20 Transactions”Creating Transactions for Tron Tokens works nearly the same. The only difference is that you will need to provide the privateKey intead of the password parameter.
Parameters
Section titled “Parameters”- from: The sender’s address.
- to: The recipient’s address.
- amount: The amount to send.
- contractaddress: The contract address of the token.
- privateKey: The private key of the sender’s address.
Example Authorization Header
Section titled “Example Authorization Header”Replace YOUR_API_TOKEN with your actual API token.
Example Code
Section titled “Example Code”curl --request POST\ --url https://api.chaingateway.io/v2/tron/transactions/trc20\ --header 'Accept: application/json'\ --header 'content-type: application/json'\ --header 'Authorization: YOUR_API_TOKEN'\ --data '{ "from": "TYourSenderAddress", "to": "TRecipientAddress", "amount": "100", "contractaddress": "TTokenContractAddress", "privateKey": "YourPrivateKey"}'import requests
url = "https://api.chaingateway.io/v2/tron/transactions/trc20"payload = { "from": "TYourSenderAddress", "to": "TRecipientAddress", "amount": "100", "contractaddress": "TTokenContractAddress", "privateKey": "YourPrivateKey"}headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'}
response = requests.post(url, json=payload, headers=headers)print(response.json())const axios = require('axios');
const url = 'https://api.chaingateway.io/v2/tron/transactions/trc20';const payload = { from: 'TYourSenderAddress', to: 'TRecipientAddress', amount: '100', contractaddress: 'TTokenContractAddress', privateKey: 'YourPrivateKey'};const headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'};
axios.post(url, payload, { headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });<?phprequire 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();$response = $client->post('https://api.chaingateway.io/v2/tron/transactions/trc20', [ 'headers' => [ 'Accept' => 'application/json', 'content-type' => 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ], 'json' => [ 'from' => 'TYourSenderAddress', 'to' => 'TRecipientAddress', 'amount' => '100', 'contractaddress' => 'TTokenContractAddress', 'privateKey' => 'YourPrivateKey' ]]);
echo $response->getBody();?>The code should return this response:
{ "status": 201, "ok": true, "message": "Succesfully created transaction", "data": { "txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27" }}