API 概述 API Overview

本API提供TRX能量委托服务,支持将能量资源委托给指定的TRON地址。使用前需要先获取API Token进行身份认证。 This API provides TRX energy delegation service, supporting delegation of energy resources to specified TRON addresses. You need to obtain an API Token for authentication before use.

基础URL:Base URL: https://api.trx-api.com

认证说明 Authentication

所有API请求都需要在请求头中包含有效的Bearer Token进行身份认证。 All API requests require a valid Bearer Token in the request header for authentication.

获取 API Token Get API Token

  1. 登录到管理面板Login to the admin panel
  2. 进入"API Tokens"页面Go to "API Tokens" page
  3. 点击"创建新Token"Click "Create New Token"
  4. 设置Token名称和权限Set token name and permissions
  5. 保存生成的Token(注意:Token只会显示一次)Save the generated token (Note: Token will only be displayed once)

使用 Token Using Token

在请求头中添加Authorization字段: Add Authorization field in request header:

Authorization: Bearer YOUR_API_TOKEN

安全提示:Security Notice: 请妥善保管您的API Token,不要在客户端代码中暴露。 Please keep your API Token secure and do not expose it in client-side code.

委托能量资源 API Energy Resource Delegation API

接口信息 Endpoint Information

请求方法:Request Method: POST

请求路径:Request Path: /api/tron/delegate-resource

Content-Type: application/json

请求参数 Request Parameters

参数名 Parameter 类型 Type 必填 Required 说明 Description
receiver_address string Yes 接收能量的TRON地址(34位字符) TRON address to receive energy (34 characters)
amount numeric Yes 交易笔数(表示需要获取多少笔交易的能量,最小值:1) Number of transactions (indicates how much energy is needed for transactions, minimum: 1)
time numeric No 租赁时间(分钟),支持 10 或 1440,默认 10 Rental time (minutes), supports 10 or 1440, default 10
activate_address boolean No 是否自动激活地址,设为 true 时系统会检查目标地址是否已激活,如未激活则自动发送1 TRX激活地址(费用1.5 TRX),默认 false Whether to automatically activate the address. When set to true, the system will check if the target address is activated, and if not, automatically send 1 TRX to activate it (cost 1.5 TRX), default false

请求示例 Request Example

curl -X POST https://api.trx-api.com/api/tron/delegate-resource \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "receiver_address": "TYourTronAddressHere1234567890123",
    "amount": 1,
    "time": 10,
    "activate_address": false
  }'

响应示例 Response Examples

成功响应 (200 OK) Success Response (200 OK)

{
    "success": true,
    "message": "资源委托成功",
    "txid": "1234567890abcdef..."
}

失败响应示例 Error Response Examples

参数验证失败 (400 Bad Request): Parameter validation failed (400 Bad Request):

{
    "success": false,
    "error": "参数验证失败",
    "details": {
        "receiver_address": ["The receiver address field is required."],
        "amount": ["The amount must be at least 1."]
    }
}

余额不足 (501 Not Implemented): Insufficient balance (501 Not Implemented):

{
    "success": false,
    "error": "余额不足,请先充值"
}

能量不足 (501 Not Implemented): Insufficient energy (501 Not Implemented):

{
    "success": false,
    "error": "能量不足,请稍后再试"
}

计费说明 Billing Information

  • 订阅套餐优先:Subscription Priority: 如果您有有效的订阅套餐且剩余次数充足,将优先使用套餐次数,不额外扣费 If you have a valid subscription with sufficient remaining quota, it will be used first without additional charges
  • 余额支付:Balance Payment: 如果没有可用套餐,将从账户余额扣除,费用为:交易笔数 × 3 TRX If no subscription is available, the fee will be deducted from account balance: transactions × 3 TRX
  • 能量说明:Energy Description: 1笔交易 = 67,000+ 能量,委托后1小时自动回收 1 transaction = 67,000+ energy, automatically reclaimed after 1 hour
  • 参数说明:Parameter Description: amount参数表示您需要多少笔交易的能量(例如:amount=1 表示获取1笔交易所需的67,000+能量) The amount parameter indicates how much energy you need for transactions (e.g., amount=1 means 67,000+ energy needed for 1 transaction)
  • 地址激活:Address Activation: 当activate_address设为true时,系统会自动检查目标地址是否已激活,如果未激活则会发送1 TRX进行激活(收费1.5 TRX) When activate_address is set to true, the system will automatically check if the target address is activated, and if not, send 1 TRX to activate it (charged 1.5 TRX)

获取用户余额 API Get User Balance API

接口信息 Endpoint Information

请求方法:Request Method: GET

请求路径:Request Path: /api/user/balance

限流:Rate Limit: 每个用户5秒内最多请求1次1 request per user every 5 seconds

请求说明 Request Description

该接口用于获取当前登录用户的余额信息。不需要任何请求参数,只需要在请求头中包含有效的Bearer Token。 This endpoint retrieves the balance information of the currently logged-in user. No request parameters are required, only a valid Bearer Token in the request header.

限流说明:Rate Limit Note: 为了防止频繁查询,每个用户5秒内最多只能请求1次。频繁请求会返回429状态码。 To prevent frequent queries, each user can only make 1 request every 5 seconds. Frequent requests will return a 429 status code.

请求示例 Request Example

curl -X GET https://api.trx-api.com/api/user/balance \
  -H "Authorization: Bearer YOUR_API_TOKEN"

响应示例 Response Examples

成功响应 (200 OK) Success Response (200 OK)

{
    "success": true,
    "data": {
        "balance": 100.50,
        "updated_at": "2025-09-13T10:30:00.000000Z"
    }
}

失败响应示例 Error Response Examples

未登录 (401 Unauthorized): Not logged in (401 Unauthorized):

{
    "success": false,
    "error": "用户未登录"
}

请求过于频繁 (429 Too Many Requests): Too many requests (429 Too Many Requests):

{
    "success": false,
    "error": "请求过于频繁,请5秒后再试"
}

服务器错误 (500 Internal Server Error): Server error (500 Internal Server Error):

{
    "success": false,
    "error": "获取余额失败: 具体错误信息"
}

响应字段说明 Response Fields

字段名 Field 类型 Type 说明 Description
success boolean 请求是否成功 Whether the request was successful
data.balance number 用户余额(TRX) User balance (TRX)
data.updated_at string 余额最后更新时间(ISO 8601格式) Last balance update time (ISO 8601 format)
error string 错误信息(仅在失败时返回) Error message (returned only on failure)

使用场景 Use Cases

  • 在委托能量前检查账户余额是否充足 Check account balance before delegating energy
  • 在用户界面显示当前余额 Display current balance in user interface
  • 监控账户余额变化 Monitor account balance changes
  • 余额不足时提醒用户充值 Remind users to recharge when balance is insufficient

代码示例 Code Examples

PHP 示例 PHP Example

<?php
$apiToken = 'YOUR_API_TOKEN';
$apiUrl = 'https://api.trx-api.com/api/tron/delegate-resource';

$data = [
    'receiver_address' => 'TYourTronAddressHere1234567890123',
    'amount' => 1,  // 1笔交易所需的能量
    'time' => 10,   // 租赁时间(分钟),10 或 1440
    'activate_address' => false  // 是否自动激活地址
];

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiToken,
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($httpCode === 200 && $result['success']) {
    echo "委托成功!交易ID: " . $result['txid'];
} else {
    echo "委托失败: " . $result['error'];
}
<?php
$apiToken = 'YOUR_API_TOKEN';
$apiUrl = 'https://api.trx-api.com/api/tron/delegate-resource';

$data = [
    'receiver_address' => 'TYourTronAddressHere1234567890123',
    'amount' => 1,  // Energy needed for 1 transaction
    'time' => 10,   // Rental time (minutes), 10 or 1440
    'activate_address' => false  // Whether to automatically activate address
];

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiToken,
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($httpCode === 200 && $result['success']) {
    echo "Delegation successful! Transaction ID: " . $result['txid'];
} else {
    echo "Delegation failed: " . $result['error'];
}

JavaScript (Node.js) 示例 JavaScript (Node.js) Example

const axios = require('axios');

const apiToken = 'YOUR_API_TOKEN';
const apiUrl = 'https://api.trx-api.com/api/tron/delegate-resource';

async function delegateEnergy() {
    try {
        const response = await axios.post(apiUrl, {
            receiver_address: 'TYourTronAddressHere1234567890123',
            amount: 1,  // 1笔交易所需的能量
            time: 10,   // 租赁时间(分钟),10 或 1440
            activate_address: false  // 是否自动激活地址
        }, {
            headers: {
                'Authorization': `Bearer ${apiToken}`,
                'Content-Type': 'application/json'
            }
        });

        if (response.data.success) {
            console.log('委托成功!交易ID:', response.data.txid);
        }
    } catch (error) {
        console.error('委托失败:', error.response?.data?.error || error.message);
    }
}

delegateEnergy();
const axios = require('axios');

const apiToken = 'YOUR_API_TOKEN';
const apiUrl = 'https://api.trx-api.com/api/tron/delegate-resource';

async function delegateEnergy() {
    try {
        const response = await axios.post(apiUrl, {
            receiver_address: 'TYourTronAddressHere1234567890123',
            amount: 1,  // Energy needed for 1 transaction
            time: 10,   // Rental time (minutes), 10 or 1440
            activate_address: false  // Whether to automatically activate address
        }, {
            headers: {
                'Authorization': `Bearer ${apiToken}`,
                'Content-Type': 'application/json'
            }
        });

        if (response.data.success) {
            console.log('Delegation successful! Transaction ID:', response.data.txid);
        }
    } catch (error) {
        console.error('Delegation failed:', error.response?.data?.error || error.message);
    }
}

delegateEnergy();

Python 示例 Python Example

import requests
import json

api_token = 'YOUR_API_TOKEN'
api_url = 'https://api.trx-api.com/api/tron/delegate-resource'

headers = {
    'Authorization': f'Bearer {api_token}',
    'Content-Type': 'application/json'
}

data = {
    'receiver_address': 'TYourTronAddressHere1234567890123',
    'amount': 1,  # 1笔交易所需的能量
    'time': 10,   # 租赁时间(分钟),10 或 1440
    'activate_address': False  # 是否自动激活地址
}

response = requests.post(api_url, headers=headers, json=data)
result = response.json()

if response.status_code == 200 and result.get('success'):
    print(f"委托成功!交易ID: {result['txid']}")
else:
    print(f"委托失败: {result.get('error', '未知错误')}")
import requests
import json

api_token = 'YOUR_API_TOKEN'
api_url = 'https://api.trx-api.com/api/tron/delegate-resource'

headers = {
    'Authorization': f'Bearer {api_token}',
    'Content-Type': 'application/json'
}

data = {
    'receiver_address': 'TYourTronAddressHere1234567890123',
    'amount': 1,  # Energy needed for 1 transaction
    'time': 10,   # Rental time (minutes), 10 or 1440
    'activate_address': False  # Whether to automatically activate address
}

response = requests.post(api_url, headers=headers, json=data)
result = response.json()

if response.status_code == 200 and result.get('success'):
    print(f"Delegation successful! Transaction ID: {result['txid']}")
else:
    print(f"Delegation failed: {result.get('error', 'Unknown error')}")

获取用户余额 - PHP 示例 Get User Balance - PHP Example

<?php
$apiToken = 'YOUR_API_TOKEN';
$apiUrl = 'https://api.trx-api.com/api/user/balance';

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiToken
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($httpCode === 200 && $result['success']) {
    echo "当前余额: " . $result['data']['balance'] . " TRX";
    echo "更新时间: " . $result['data']['updated_at'];
} elseif ($httpCode === 429) {
    echo "请求过于频繁,请5秒后再试";
} else {
    echo "获取余额失败: " . $result['error'];
}
<?php
$apiToken = 'YOUR_API_TOKEN';
$apiUrl = 'https://api.trx-api.com/api/user/balance';

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiToken
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($httpCode === 200 && $result['success']) {
    echo "Current balance: " . $result['data']['balance'] . " TRX";
    echo "Updated at: " . $result['data']['updated_at'];
} elseif ($httpCode === 429) {
    echo "Too many requests, please try again in 5 seconds";
} else {
    echo "Failed to get balance: " . $result['error'];
}

获取用户余额 - JavaScript 示例 Get User Balance - JavaScript Example

const axios = require('axios');

const apiToken = 'YOUR_API_TOKEN';
const apiUrl = 'https://api.trx-api.com/api/user/balance';

async function getUserBalance() {
    try {
        const response = await axios.get(apiUrl, {
            headers: {
                'Authorization': `Bearer ${apiToken}`
            }
        });

        if (response.data.success) {
            console.log('当前余额:', response.data.data.balance, 'TRX');
            console.log('更新时间:', response.data.data.updated_at);
        }
    } catch (error) {
        if (error.response?.status === 429) {
            console.error('请求过于频繁,请5秒后再试');
        } else {
            console.error('获取余额失败:', error.response?.data?.error || error.message);
        }
    }
}

getUserBalance();
const axios = require('axios');

const apiToken = 'YOUR_API_TOKEN';
const apiUrl = 'https://api.trx-api.com/api/user/balance';

async function getUserBalance() {
    try {
        const response = await axios.get(apiUrl, {
            headers: {
                'Authorization': `Bearer ${apiToken}`
            }
        });

        if (response.data.success) {
            console.log('Current balance:', response.data.data.balance, 'TRX');
            console.log('Updated at:', response.data.data.updated_at);
        }
    } catch (error) {
        if (error.response?.status === 429) {
            console.error('Too many requests, please try again in 5 seconds');
        } else {
            console.error('Failed to get balance:', error.response?.data?.error || error.message);
        }
    }
}

getUserBalance();

获取用户余额 - Python 示例 Get User Balance - Python Example

import requests

api_token = 'YOUR_API_TOKEN'
api_url = 'https://api.trx-api.com/api/user/balance'

headers = {
    'Authorization': f'Bearer {api_token}'
}

response = requests.get(api_url, headers=headers)
result = response.json()

if response.status_code == 200 and result.get('success'):
    print(f"当前余额: {result['data']['balance']} TRX")
    print(f"更新时间: {result['data']['updated_at']}")
elif response.status_code == 429:
    print("请求过于频繁,请5秒后再试")
else:
    print(f"获取余额失败: {result.get('error', '未知错误')}")
import requests

api_token = 'YOUR_API_TOKEN'
api_url = 'https://api.trx-api.com/api/user/balance'

headers = {
    'Authorization': f'Bearer {api_token}'
}

response = requests.get(api_url, headers=headers)
result = response.json()

if response.status_code == 200 and result.get('success'):
    print(f"Current balance: {result['data']['balance']} TRX")
    print(f"Updated at: {result['data']['updated_at']}")
elif response.status_code == 429:
    print("Too many requests, please try again in 5 seconds")
else:
    print(f"Failed to get balance: {result.get('error', 'Unknown error')}")

错误码说明 Error Codes

HTTP状态码 HTTP Status Code 说明 Description 可能的原因 Possible Causes
200 成功 Success 请求成功处理 Request processed successfully
400 请求错误 Bad Request 参数验证失败、地址格式错误 Parameter validation failed, invalid address format
401 未授权 Unauthorized 未提供Token或Token无效 No token provided or invalid token
429 请求过于频繁 Too Many Requests 超出限流控制,5秒内请求过多 Rate limit exceeded, too many requests within 5 seconds
500 服务器错误 Server Error 服务器内部错误 Internal server error
501 资源不足 Insufficient Resources 余额不足或能量不足 Insufficient balance or energy

注意事项 Important Notes

  • API Token 请妥善保管,避免泄露 Keep your API Token secure and avoid leakage
  • 接收地址必须是有效的TRON地址(34位字符) Receiver address must be a valid TRON address (34 characters)
  • 委托的能量将在1小时后自动回收 Delegated energy will be automatically reclaimed after 1 hour
  • 如遇到"能量不足"错误,请等待10分钟后重试 If you encounter "Insufficient energy" error, please wait 10 minutes and try again
  • 建议在生产环境中实现错误重试机制 It is recommended to implement error retry mechanism in production environment
  • API调用频率限制:每分钟最多60次请求 API rate limit: Maximum 60 requests per minute