Skip to content

Create Token Transactions

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

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.

  • 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.

Replace YOUR_API_TOKEN with your actual API token.

Terminal window
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"
}'

The code should return this response:

{
"status": 201,
"ok": true,
"message": "Succesfully created transaction",
"data": {
"txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27"
}
}

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.

  • 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.

Replace YOUR_API_TOKEN with your actual API token.

Terminal window
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"
}'

The code should return this response:

{
"status": 201,
"ok": true,
"message": "Succesfully created transaction",
"data": {
"txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27"
}
}