Quickstart Guide
This guide helps you making your first steps in Chaingateway. It describes you how to read the api docs, create an api key and authorize you to use our api.
Get Up and running with the Chaingateway API
The Chaingateway API provides an simple interface for developers to interact with multiple blockchains like Tron, Binance Smart Chain (BNB Chain), Ethereum , Polygon and Bitcoin. Our API endpoints provides you with several functionalities like creating transactions, sending fungible and non-fungible tokens and query useful blockchain data such as account balances and blocks heights.
Get Up and running with the Chaingateway API
The Chaingateway API provides a simple interface for developers to interact with multiple blockchains like Tron, Binance Smart Chain (BNB Chain), Ethereum, Polygon, and Bitcoin. Our API endpoints provide several functionalities like creating transactions, sending fungible and non-fungible tokens, and querying useful blockchain data such as account balances and block heights.
- How to setup your account
- How to create your API key
- The basic concepts behind our API
- How to send your first API Request
Account setup
First, create a Chaingateway Account or sign in. Next, navigate to the API key page to create a new token. Type in a name for your token and hit "+ Create Token". Your new Token should now be visible on the UI. Please store it in a safe place and do not give this token to others!
Quickstart language
During the next sections, you have the possibility to choose your programming language between curl, php, nodejs, and python. In case you need code examples for other languages, our API reference supports a lot of other languages.
Setup your development environment
To create API calls to Chaingateway, you need an HTTP client. For some popular programming languages, we will link you tutorials here:
- CURL for command line interfaces like bash or shell
- Requests for Python
- Axios for JavaScript and Node.js
- Guzzle for PHP
- HTTP client for Laravel
We recommend using a central storage for our API key, which could be an environment variable for curl and python or an .env file for Node.js and PHP/Laravel.
Basic API Concept
REST
Chaingateway's REST API follows the principles of REST, using HTTP requests to communicate. It offers endpoints representing resources, like /addresses, and supports standard methods like GET, POST, PUT, DELETE for actions such as retrieving, creating, updating, and deleting resources. Responses are typically in JSON format. Authentication ensures secure access to resources.
Let's make an example with the address resource:
GET: Retrieve address data by sending a GET request to
/addresses
for a list of addresses or/addresses/{id}
for a specific address.POST: Create a new address by sending a POST request to
/addresses
with the address details in the request body.PUT: Update an existing address by sending a PUT request to
/addresses/{id}
with the complete updated address information in the request body. As updating any address information is not allowed on blockchains, this method does not exist.DELETE: Remove an address by sending a DELETE request to
/addresses/{id}
.PATCH: Make partial updates to an address by sending a PATCH request to
/addresses/{id}
with only the specific changes. As updating any address information is not allowed on blockchains, this method does not exist.
These methods allow clients to perform CRUD operations on various resources in a predictable and consistent manner, adhering to REST principles. You need to ensure that the method always fits your needed functionality.
Headers
HTTP headers provide additional information about the request or response. Here are some commonly used headers:
Authorization Header: The Authorization header is used to send credentials (such as a token or username/password) along with a request to access protected resources. For example,
Authorization: <token>
indicates that the request is authorized using a token.Accept Header: The Accept header specifies the media types that the client is willing to receive in the response. It helps the server understand what kind of content the client prefers. For instance,
Accept: application/json
tells the server that the client prefers JSON-formatted responses. Multiple media types can be specified, separated by commas, and the server will choose the most appropriate one based on its capabilities and the preferences expressed by the client.Content-Type Header: The Content-Type header indicates the media type of the request body being sent to the server. It tells the server how to interpret the data in the request. For example,
Content-Type: application/json
indicates that the request body is formatted as JSON. This header is particularly important for POST and PUT requests, where the client is sending data to the server.
Make your first API request
After you have configured your HTTP client and understood how the API works, we can start using it in our project. To show you how our API works, we will first create an Ethereum address.
Let's break down the different components of this API call:
We use the POST method because we want to submit data to the API.
The data we send is defined in the request body {"password": "architecto"}
. It's a JSON object with a key-value pair where the key is "password" and the value is "architecto". This data will be processed by the server according to the API's specifications.
The Authorization Header adds an Authorization header with a value of "YOUR_SECRET_TOKEN" (replace this with your own token!). The Content-Type and Accept both are set to application/json, ensuring that both systems want to communicate with the application/json filetype.
curl --request POST \
--url http://api.chaingateway.io/api/v2/ethereum/addresses \
--header 'Authorization: YOUR_SECRET_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"password": "architecto"
}'
import requests
url = "http://api.chaingateway.io/api/v2/ethereum/addresses"
payload = { "password": "architecto" }
headers = {
"Content-Type": "application/json",
"Authorization": "YOUR_SECRET_TOKEN"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
import axios from 'axios';
const options = {
method: 'POST',
url: 'http://api.chaingateway.io/api/v2/ethereum/addresses',
headers: {'Content-Type': 'application/json', Authorization: 'YOUR_SECRET_TOKEN'},
data: {password: 'architecto'}
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.chaingateway.io/api/v2/ethereum/addresses', [
'body' => '{
"password": "architecto"
}',
'headers' => [
'Authorization' => 'YOUR_SECRET_TOKEN',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();
The response will be:
{
"status": 201,
"ok": true,
"message": "Address created",
"data": {}
}
To fetch data such as getting a list of addresses, you can utilize the GET method. This method usually doesn't use any request body.
curl --request GET \
--url https://api.chaingateway.io/api/v2/ethereum/addresses \
--header 'Authorization: YOUR_SECRET_TOKEN'
import requests
url = "https://api.chaingateway.io/api/v2/ethereum/addresses"
headers = {"Authorization": "YOUR_SECRET_TOKEN"}
response = requests.get(url, headers=headers)
print(response.json())
import axios from 'axios';
const options = {
method: 'GET',
headers: {Authorization: 'YOUR_SECRET_TOKEN'}
};
try {
const { data } = await axios.request(options);
console.log(data);
} catch (error) {
console.error(error);
}
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.chaingateway.io/api/v2/ethereum/addresses', [
'headers' => [],
]);
echo $response->getBody();
The response will be:
{
"ok": true
}