Skip to content

Create Addresses

Introduction

In this tutorial, we will cover how to create addresses for Polygon, Binance Smart Chain, Ethereum, and Tron using Chaingateway. We will provide examples in various programming languages, including Shell (cURL), PHP (Guzzle), Python (Requests), and JavaScript (Axios). In this tutorial, we will cover how to create addresses for Polygon, Binance Smart Chain, Ethereum, and Tron using Chaingateway. We will provide examples in various programming languages, including Shell (cURL), PHP (Guzzle), Python (Requests), and JavaScript (Axios). For obtaining an API key and learning about authorization, please refer to the Quickstart section of the Chaingateway documentation.

Creating Addresses for Polygon, Binance Smart Chain, and Ethereum

When creating a new address for an EVM based blockchain, we need to create a keystore. This is a security mechanism to keep your information safe. The keystore will be encrypted with a password. With this mechanism, you do not need to send your private key within your transaction payload but only your password. A person that has only the keystore file or only the password cannot access the address.

To create the address, send a request to the Chaingateway API.

Parameters

  • password: This is a user-defined password for the new address. It is used to secure the address and will be required for performing transactions with this address. It is essential to store this password securely as Chaingateway does not store or have access to it. If the password is lost, the address cannot be accessed.

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 or /polygon 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/addresses\
    --header 'Accept: application/json'\
    --header 'content-type: application/json'\
    --header 'Authorization: YOUR_API_TOKEN'\
    --data '{"password":"test123"}'
python
import requests

url = "https://api.chaingateway.io/v2/ethereum/addresses"
payload = {"password": "test123"}
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/addresses';
const payload = { password: 'test123' };
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/addresses', [
        'headers' => [
                'Accept' => 'application/json',
                'content-type' => 'application/json',
                'Authorization' => 'YOUR_API_TOKEN',
        ],
        'json' => ['password' => 'test123']
]);

echo $response->getBody();
?>

Response

json
{
    "status": 201,
    "ok": true,
    "message": "Address created",
    "data": {
        "adderess": "0x7d3bC832A0860fD882FF4C2359e10268f4E5CCf8"
    }
}

Creating Addresses for Tron

No parameters are required in the body of the request for creating a Tron address. The response will include the private key, the base58 check address (readable address), and the hexadecimal address. The private key is crucial for accessing and performing transactions with the Tron address. It should be stored securely as ChainGateway does not store or have access to it.

Example Authorization Header

Replace YOUR_API_TOKEN with your actual API token.

Example Code

curl
curl --request POST\
  --url https://api.chaingateway.io/v2/tron/addresses\
  --header 'Accept: application/json'\
  --header 'content-type: application/json'\
  --header 'Authorization: YOUR_API_TOKEN'
python

import requests

url = "https://api.chaingateway.io/v2/tron/addresses"
headers = {
    'Accept': 'application/json',
    'content-type': 'application/json',
    'Authorization': 'YOUR_API_TOKEN'
}

response = requests.post(url, headers=headers)
print(response.json())
javascript

const axios = require('axios');

const url = 'https://api.chaingateway.io/v2/tron/addresses';
const headers = {
  'Accept': 'application/json',
  'content-type': 'application/json',
  'Authorization': 'YOUR_API_TOKEN'
};

axios.post(url, {}, { 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/addresses', [
    'headers' => [
        'Accept' => 'application/json',
        'content-type' => 'application/json',
        'Authorization' => 'YOUR_API_TOKEN',
    ]
]);

echo $response->getBody();
?>

The response should look like this:

json
{
    "status": 201,
    "ok": true,
    "message": "Address created",
    "data": {
      "privateKey": "59f1c6200e01a2ca9471411f10198bfa63678d0e87cc2ca30f9c4a68dee78edc",
      "publicKey": "040fe6e677442c36f7fdd5535ba3ff1cef0110d78363420f7e24b65298990e3467aed68b9a67e1396d84753db25b32a2fa3e1fc0a673f01638e9bcfab2d8f4ceb5",
      "hexAddress": "41a56a6505ffbee78eb916dd44f4846874deddaebd",
      "address": "TR3qx91smURF3R455V1ubqtoUsZbgqikfg"
    }
}

You should store the privateKey and address on a secure place in your app

Important Information

For creating transactions, users need to provide the password of the address (for Polygon, Binance Smart Chain, and Ethereum) 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.