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)

请求示例 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
  }'

响应示例 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: 如果没有可用套餐,将从账户余额扣除,费用为:交易笔数 × 4 TRX If no subscription is available, the fee will be deducted from account balance: transactions × 4 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)

代码示例 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笔交易所需的能量
];

$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
];

$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笔交易所需的能量
        }, {
            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
        }, {
            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笔交易所需的能量
}

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
}

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')}")

错误码说明 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
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