Transfer small amounts of TRX
interface address
POST /api/v1/frontend/order/transfer
Request parameters
Parameter name | Type | Required | Description | Example |
---|---|---|---|---|
amount | int | Yes | Required TRX, unit sun, between 100000 - 10000000 That is, between 0.1-10 TRX | 345000 |
receive_address | Tron address | Yes | The address needs to be activated, otherwise the order will fail |
Return parameters
- Normal return example
{
"errno": 0,
"txid": "9df44479551ef93c9bbfeca3cb82ef1564199d2d492ad38f7f1d2e454f5efb0f",
"balance": 813900029257
}
For exception returns, please refer to API return value
Field explanation
Parameter name | Type | Description | Example |
---|---|---|---|
errno | int | Error code, normal when it is 0 | |
message | string | Error reason, if errno > 0 | |
txid | string | txid on the chain | |
balance | int | Balance, in sun, needs to be divided by 1000000 to convert to TRX |
Code Example
import hmac
import json
import requests
import hashlib
import time
API_KEY = "B433BFF1CDE7450AA38A56BEAC690DD4"
API_SECRET = "0285A2741D0E76E2E187260EB23E51851D48403A756333E7D0CF845406ABF3E8"
timestamp = str(int(time.time()))
URL = "https://itrx.io/api/v1/frontend/order/transfer"
data = {
'amount': 345000,
'receive_address': 'TExWKszFWYTKZH8LYiovAPKzS3L9MLZ4kw',,
}
json_data = json.dumps(data, sort_keys=True, separators=(',', ':'))
message = f'{timestamp}&{json_data}'
signature = hmac.new(API_SECRET.encode(), message.encode(), hashlib.sha256).hexdigest()
headers = {
"API-KEY": API_KEY,
"TIMESTAMP": timestamp,
"SIGNATURE": signature,
'Content-Type': 'application/json',
}
response = requests.post(f"{URL}", data=json_data, headers=headers)
print(response.json())
<?php
$API_KEY = "B433BFF1CDE7450AA38A56BEAC690DD4";
$API_SECRET = "0285A2741D0E76E2E187260EB23E51851D48403A756333E7D0CF845406ABF3E8";
$timestamp = time();
$data = [
'amount' => 345000,
'receive_address' => 'TExWKszFWYTKZH8LYiovAPKzS3L9MLZ4kw',
];
ksort($data);
$json_data = json_encode($data, JSON_UNESCAPED_SLASHES);
$message = $timestamp . '&' . $json_data;
$signature = hash_hmac('sha256', $message, $API_SECRET);
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n" .
"API-KEY: $API_KEY\r\n" .
"TIMESTAMP: $timestamp\r\n" .
"SIGNATURE: $signature\r\n",
'method' => 'POST',
'content' => $json_data,
],
];
$context = stream_context_create($options);
$result = file_get_contents("https://itrx.io/api/v1/frontend/order/transfer", false, $context);
var_dump($result);
?>
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.*;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class Main {
private static final String API_KEY = "B433BFF1CDE7450AA38A56BEAC690DD4";
private static final String API_SECRET = "0285A2741D0E76E2E187260EB23E51851D48403A756333E7D0CF845406ABF3E8";
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
String timestamp = String.valueOf(Instant.now().getEpochSecond());
Map<String, Object> data = new HashMap<>();
data.put("amount", 345000);
data.put("receive_address", "TExWKszFWYTKZH8LYiovAPKzS3L9MLZ4kw");
// Sorting the keys
TreeMap<String, Object> sortedData = new TreeMap<>(data);
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
String json_data = gson.toJson(sortedData);
String message = timestamp + "&" + json_data;
String signature = encodeHmacSHA256(message, API_SECRET);
RequestBody body = RequestBody.create(json_data, mediaType);
Request request = new Request.Builder()
.url("https://itrx.io/api/v1/frontend/order/transfer")
.method("POST", body)
.addHeader("API-KEY", API_KEY)
.addHeader("TIMESTAMP", timestamp)
.addHeader("SIGNATURE", signature)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
private static String encodeHmacSHA256(String data, String key) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] bytes = sha256_HMAC.doFinal(data.getBytes(StandardCharsets.UTF_8));
StringBuilder hash = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xff & b);
if(hex.length() == 1) hash.append('0');
hash.append(hex);
}
return hash.toString();
}
}
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
jsoniter "github.com/json-iterator/go"
)
const (
APIKey = "B433BFF1CDE7450AA38A56BEAC690DD4"
APISecret = "0285A2741D0E76E2E187260EB23E51851D48403A756333E7D0CF845406ABF3E8"
URL = "https://itrx.io/api/v1/frontend/order/transfer"
)
type Data struct {
Amount int `json:"amount"`
ReceiveAddress string `json:"receive_address"`
}
func main() {
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
data := Data{
Amount: 345000,
ReceiveAddress: "TExWKszFWYTKZH8LYiovAPKzS3L9MLZ4kw",
}
json := jsoniter.ConfigCompatibleWithStandardLibrary
b, err := json.Marshal(data)
if err != nil {
panic(err)
}
json_data := string(b)
message := timestamp + "&" + json_data
signature := createHmac(message, APISecret)
client := &http.Client{}
req, err := http.NewRequest("POST", URL, bytes.NewBuffer([]byte(json_data)))
if err != nil {
panic(err)
}
req.Header.Set("API-KEY", APIKey)
req.Header.Set("TIMESTAMP", timestamp)
req.Header.Set("SIGNATURE", signature)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(respBody))
}
func createHmac(message string, secret string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(message))
return hex.EncodeToString(h.Sum(nil))
}
#!/bin/bash
API_KEY="B433BFF1CDE7450AA38A56BEAC690DD4"
API_SECRET="0285A2741D0E76E2E187260EB23E51851D48403A756333E7D0CF845406ABF3E8"
URL="https://itrx.io/api/v1/frontend/order/transfer"
timestamp=$(date +%s)
data=$(echo '{
"amount": 345000,
"receive_address": "TExWKszFWYTKZH8LYiovAPKzS3L9MLZ4kw",
}' | jq -c -S '.')
message="${timestamp}&${data}"
signature=$(echo -n "${message}" | openssl dgst -sha256 -hmac ${API_SECRET} -binary | xxd -p)
curl --location --request POST ${URL} \
--header "API-KEY: ${API_KEY}" \
--header "TIMESTAMP: ${timestamp}" \
--header "SIGNATURE: ${signature}" \
--header "Content-Type: application/json" \
--data-raw "${data}"