Skip to content

Create Native Token Transactions

Introduction

In this tutorial, we will cover how to make transactions for Ethereum (ETH), Binance Smart Chain (BNB), Polygon (MATIC), Tron (TRX), and Bitcoin (BTC) using the ChainGateway V2 API. We will provide examples in various programming languages, including Shell (cURL), PHP, Python, and JavaScript.

In this tutorial we will create transactions for the native tokens ETH BNB TRX MATIC. For sending TRC20, ERC20, and BEP20 transactions, please visit Create Token Transactions

For obtaining an API key and learning about authorization, please refer to the Quickstart section of the Chaingateway documentation.

Creating Transactions for ETH, BNB, and MATIC

When making a transaction on Ethereum, Binance Smart Chain, or Polygon, you need to send a request to the ChainGateway API with the appropriate parameters.

Parameters

  • from: The sender's address.
  • to: The recipient's address.
  • amount: The amount to send.
  • password: The password used to encrypt the keystore file of the sender's address.

Example Authorization Header

Replace YOUR_API_TOKEN with your actual API token.

Example Code

Usage for other Blockhains and networks

This code example is using /ethereum in the route as an example. feel free to just replace it with /bsc, /polygon or /bitcoin for creating it on other networks.

you can also replace https://api.chaingateway.io with https://testnet.chaingateway.io to switch to the testnet networks.

shell
curl --request POST\
  --url https://api.chaingateway.io/v2/ethereum/transactions\
  --header 'Accept: application/json'\
  --header 'content-type: application/json'\
  --header 'Authorization: YOUR_API_TOKEN'\
  --data '{
    "from": "0xYourSenderAddress",
    "to": "0xRecipientAddress",
    "amount": "0.1",
    "password": "YourPassword"
}'
python
import requests

url = "https://api.chaingateway.io/v2/ethereum/transactions"
payload = {
    "from": "0xYourSenderAddress",
    "to": "0xRecipientAddress",
    "amount": "0.1",
    "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())
javascript
const axios = require('axios');

const url = 'https://api.chaingateway.io/v2/ethereum/transactions';
const payload = {
  from: '0xYourSenderAddress',
  to: '0xRecipientAddress',
  amount: '0.1',
  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);
  });
php
<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$response = $client->post('https://api.chaingateway.io/v2/ethereum/transactions', [
    'headers' => [
        'Accept' => 'application/json',
        'content-type' => 'application/json',
        'Authorization' => 'YOUR_API_TOKEN',
    ],
    'json' => [
        'from' => '0xYourSenderAddress',
        'to' => '0xRecipientAddress',
        'amount' => '0.1',
        'password' => 'YourPassword'
    ]
]);

echo $response->getBody();
?>

The code should return this response:

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

Creating Transactions for TRX

Parameters

  • from: The sender's address.
  • to: The recipient's address.
  • amount: The amount to send.
  • privateKey: The private key of the sender's address.

Example Authorization Header

Replace YOUR_API_TOKEN with your actual API token.

Example Code

shell
curl --request POST\
  --url https://api.chaingateway.io/v2/tron/transactions\
  --header 'Accept: application/json'\
  --header 'content-type: application/json'\
  --header 'Authorization: YOUR_API_TOKEN'\
  --data '{
    "from": "YourSenderAddress",
    "to": "RecipientAddress",
    "amount": "0.001",
    "privateKey": "YourPrivateKey"
}'

```python

import requests

url = "https://api.chaingateway.io/v2/tron/transactions"
payload = {
    "from": "YourSenderAddress",
    "to": "RecipientAddress",
    "amount": "0.001",
    "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())
javascript

const axios = require('axios');

const url = 'https://api.chaingateway.io/v2/tron/transactions';
const payload = {
  from: 'YourSenderAddress',
  to: 'RecipientAddress',
  amount: '0.001',
  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);
  });
php

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$response = $client->post('https://api.chaingateway.io/v2/tron/transactions', [
    'headers' => [
        'Accept' => 'application/json',
        'content-type' => 'application/json',
        'Authorization' => 'YOUR_API_TOKEN',
    ],
    'json' => [
        'from' => 'YourSenderAddress',
        'to' => 'RecipientAddress',
        'amount' => '0.001',
        'privateKey' => 'YourPrivateKey'
    ]
]);

echo $response->getBody();
?>

The code should return this response:

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

Important Information

For creating transactions, users need to provide the password of the address (for Ethereum, Binance Smart Chain, Polygon and Bitcoin) or the private key (for Tron). ChainGateway does not store these sensitive pieces of information. Therefore, users must store them in a safe place. If these are lost, ChainGateway cannot assist in recovery as it does not have access to this information.

For obtaining an API key and learning about authorization, please refer to the Getting Started section of the ChainGateway documentation.