Tài liệu API REST đầy đủ cho việc ủy quyền Energy TronEnergy . Bao gồm các điểm cuối, tham số, định dạng phản hồi và mã lỗi.
URL cơ sở:https://api.tronnrg.comXác thực: Không yêu cầu gì cả. Tất cả các điểm cuối đều công khai.
Giới hạn tốc độ: 20 yêu cầu/giây cho mỗi địa chỉ IP
Địa chỉ thanh toán:TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx (Chỉ API , không áp dụng cho thuê thủ công)
Cách thức hoạt động
Ba bước đơn giản. Không cần khóa API , không cần đăng ký, không cần kết nối ví. Quyền sở hữu được chứng minh bằng mật mã.
Gửi TRX — Gửi 4 TRX (hoặc nhiều hơn) đến địa chỉ thanh toán. 4 TRX = 65.000 năng lượng. 8 TRX = 130.000. Tuyến tính.
Dấu hiệu — Ký tên vào tin nhắn {tx_hash}:{delegate_to} Sử dụng ví đã gửi TRX . Điều này chứng minh bạn đã ủy quyền cho việc chuyển giao.
Khẳng định — POST /delegate với tx_hash, delegate_to, Và signatureEnergy sẽ đến trong khoảng 3 giây.
Địa chỉ thanh toán
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
Chỉ dùng địa chỉ thanh toán API . Địa chỉ này dành cho việc tích hợp lập trình thông qua API . Không sử dụng địa chỉ này cho việc thuê năng lượng thủ công. Địa chỉ thuê thủ công khác và có trên .tronnrg.com.
Hãy gửi TRX đến địa chỉ này. Mã băm giao dịch của khoản thanh toán của bạn chính là mã thông báo để kích hoạt ủy quyền. Mỗi mã băm chỉ có thể được sử dụng một lần.
TRX đã gửi
Energy được ủy quyền
Trường hợp sử dụng
4 TRX
65,000
Giao dịch chuyển USDT tiêu chuẩn đến ví hiện có (đơn hàng tối thiểu)
8 TRX
130,000
Chuyển USDT cho người nhận lần đầu
16 TRX
260,000
Bốn lần chuyển khoản tiêu chuẩn trong một đơn hàng
40 TRX
650,000
Mười lần chuyển khoản tiêu chuẩn
100 TRX
1,625,000
~25 lượt chuyển đổi tiêu chuẩn — phổ biến đối với các sân ga nhỏ.
1,000 TRX
16,250,000
Số lượng đặt hàng tối đa: ~250 lượt chuyển khoản tiêu chuẩn
Bất kỳ số tiền nào nằm giữa
trx × 16,250
Hoàn toàn tuyến tính. Không phân cấp, không gói dịch vụ, không giảm giá.
Công thức:energy = trxSent × 16,250. Giới hạn: Tối thiểu 4 TRX (65.000 năng lượng), tối đa 1.000 TRX (16.250.000 năng lượng). Cả hai đều được thực thi ở cấp độ API — số lượng dưới mức tối thiểu sẽ bị từ chối với mã lỗi below_minimum và được hoàn trả; số lượng trên mức tối đa sẽ bị từ chối trước khi ủy quyền. Luôn đọc các giá trị thực từ lệnh GET /supply trước khi mã hóa cứng chúng trong môi trường sản xuất — xem bên dưới.
GET /supply
GET/supply
Lấy thông tin giá cả và địa chỉ thanh toán. Đây chỉ là điểm truy cập thông tin — năng lượng luôn có sẵn, bạn không cần kiểm tra trước khi gửi thanh toán.
curl https://api.tronnrg.com/supply
const supply = awaitfetch('https://api.tronnrg.com/supply')
.then(r => r.json());
// Energy is always available. Use supply.pay_to for the payment address.
console.log('Pay to:', supply.pay_to);
import requests
supply = requests.get('https://api.tronnrg.com/supply').json()
# Energy is always available. Use supply['pay_to'] for the payment address.print(supply['pay_to'])
$supply = json_decode(
file_get_contents('https://api.tronnrg.com/supply'),
true
);
// if less than you require, wait and retry// Energy is always available. Use $supply['pay_to'] for the payment address.echo$supply['pay_to'];
var client = newHttpClient();
var json = await client.GetStringAsync("https://api.tronnrg.com/supply");
var supply = JsonSerializer.Deserialize<JsonElement>(json);
// Energy is always available. Use pay_to for the payment address.var payTo = supply.GetProperty("pay_to").GetString();
Yêu cầu ủy quyền năng lượng. Bạn phải đã gửi TRX đến địa chỉ thanh toán trên chuỗi. Cung cấp mã băm giao dịch, địa chỉ người nhận và chữ ký chứng minh bạn là người gửi.
Parameter
Type
Description
tx_hash
string
required
Mã băm thập lục phân 64 ký tự của khoản thanh toán TRX
delegate_to
string
required
Địa chỉ Tron để nhận năng lượng
signature
string
required
Sign {tx_hash}:{delegate_to} using tronWeb.trx.signMessageV2(). Proves you are the payment sender.
Mã số tham chiếu TronNRG . Vui lòng ghi lại mã số này để hỗ trợ khi cần.
energy
number
Tổng năng lượng được phân bổ
cost
number
TRX đã được sạc
status
string
"được ủy quyền" khi thành công
delegations
array
On-chain delegation transaction hashes. Each tx is verifiable on TronScan. This is your receipt.
GET /health
GET/health
Liveness check for monitoring and uptime tools. Returns 200 OK when the API process is up. Does not check upstream nodes or providers.
Response 200
{ "status": "ok" }
Mã lỗi
Every error response has error (stable, machine-readable) and message (human-readable). Always switch on error.
Code
HTTP
Meaning
invalid_tx_hash
400
Không phải là chuỗi thập lục phân 64 ký tự
invalid_address
400
Đây không phải là địa chỉ Tron hợp lệ.
missing_signature
400
Không có chữ ký nào được cung cấp.
invalid_signature
401
Không thể xác minh chữ ký.
signature_mismatch
403
Địa chỉ người ký không trùng khớp với địa chỉ người gửi thanh toán.
hash_already_used
409
Mã băm giao dịch đã được sử dụng
payment_verification_failed
404 / 400
On-chain verification of the payment failed. Read the message field for the specific cause: tx not found yet (404, retry in a few seconds), wrong recipient, not a TRX transfer, or below the 4 TRX minimum.
delegation_failed
400 / 500
Provider could not deliver energy. If the failure happened after the payment was verified, an automatic refund is queued. The error response includes a refund object when this happens.
rate_limited
429
Quá nhiều yêu cầu mỗi giây từ địa chỉ IP này. Giới hạn là 20 yêu cầu/giây.
server_error
500
Lỗi nội bộ không mong muốn. Vui lòng thử lại sau vài giây.
const result = awaitfetch('https://api.tronnrg.com/delegate', { ... })
.then(r => r.json());
if (result.error) {
switch (result.error) {
case'payment_verification_failed':
// Most common cause: tx not yet indexed. Wait 3s and retry.// Read result.message for the specific cause.break;
case'hash_already_used':
// Already claimed. Don't retry.break;
case'signature_mismatch':
// Signer != payment sender. Sign with the same key that sent TRX.break;
case'delegation_failed':
// Refund queued automatically if payment was verified.if (result.refund) console.log('Refund queued:', result.refund);
break;
}
}
result = requests.post('https://api.tronnrg.com/delegate', json=data).json()
if'error'in result:
if result['error'] == 'payment_verification_failed':
# Most common cause: tx not yet indexed. Wait 3s and retry.passelif result['error'] == 'hash_already_used':
# Already claimed. Don't retry.passelif result['error'] == 'signature_mismatch':
# Signer != payment sender. Sign with the same key.passelif result['error'] == 'delegation_failed':
# Refund queued automatically if payment was verified.pass
if (isset($result['error'])) {
switch ($result['error']) {
case'payment_verification_failed':
// Most common cause: tx not yet indexed. Wait 3s and retry.break;
case'hash_already_used':
// Already claimed. Don't retry.break;
case'signature_mismatch':
// Signer != payment sender. Sign with the same key.break;
case'delegation_failed':
// Refund queued automatically if payment was verified.break;
}
}
Refunds
Nếu quá trình ủy quyền thất bại sau khi thanh toán của bạn được xác minh, một khoản hoàn tiền TRX sẽ tự động được xếp vào hàng đợi và gửi lại địa chỉ người gửi trên chuỗi. Hãy tìm đối tượng hoàn tiền trong phản hồi lỗi.
Error with refund
{
"error": "delegation_failed",
"message": "Energy delegation failed. Your payment will be refunded.",
"ref": "nrg_d_43",
"refund": {
"type": "queued",
"to": "TSenderAddress",
"amount": 4
}
}
Ví dụ hoàn chỉnh
Quy trình hoàn chỉnh từ đầu đến cuối: gửi TRX , ký, xác nhận với tùy chọn thử lại. Sao chép và sử dụng.
const API = 'https://api.tronnrg.com';
const ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx';
async functionrentEnergy(delegateTo, trxAmount = 4) {
// 1. Send TRX to the payment addressconst payment = await tronWeb.trx.sendTransaction(ADDR, trxAmount * 1e6);
// 2. Sign: proves you are the senderconst message = `${payment.txid}:${delegateTo}`;
const signature = await tronWeb.trx.signMessageV2(message);
// 3. Claim delegation (retry if tx not indexed yet)let result;
for (let i = 0; i < 3; i++) {
result = awaitfetch(`${API}/delegate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
tx_hash: payment.txid,
delegate_to: delegateTo,
signature,
}),
}).then(r => r.json());
if (!result.error) break;
if (result.error !== 'payment_verification_failed') throw newError(result.message);
await newPromise(r => setTimeout(r, 3000));
}
if (result.error) throw newError(result.message);
return result;
}
// Usage — send any amount between 4 and 1,000 TRXconst result = awaitrentEnergy('TWalletThatNeedsEnergy', 4); // 4 TRX → 65k energy// rentEnergy(addr, 8) // → 130,000 energy (new-wallet transfer)// rentEnergy(addr, 40) // → 650,000 energy (10 transfers)// rentEnergy(addr, 1000) // → 16,250,000 energy (max)
console.log(result.energy); // trxAmount × 16,250
console.log(result.delegations[0].tx); // on-chain tx hash
console.log(result.ref); // "nrg_d_42"
import requests
import time
API = 'https://api.tronnrg.com'
ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx'defrent_energy(delegate_to, trx_amount=4):
# 1. Send TRX to ADDR (via your Tron library)
tx_hash = send_trx(ADDR, trx_amount) # your TRX send function# 2. Sign: proves you are the sender
message = f'{tx_hash}:{delegate_to}'
signature = tron.trx.sign_message_v2(message)
# 3. Claim delegation (retry if tx not indexed yet)for attempt inrange(3):
result = requests.post(f'{API}/delegate', json={
'tx_hash': tx_hash,
'delegate_to': delegate_to,
'signature': signature,
}).json()
if'error'not in result:
return result
if result['error'] != 'payment_verification_failed':
raiseException(result['message'])
time.sleep(3)
raiseException('Transaction not found after retries')
# Usage
result = rent_energy('TWalletThatNeedsEnergy', 4)
print(f"Delegated: {result['energy']} energy")
print(f"Delegation tx: {result['delegations'][0]['tx']}")
print(f"Ref: {result['ref']}")
# 1. Send TRX to TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx# Pricing is linear at 16,250 energy per TRX.# Min 4 TRX (65,000 energy), max 1,000 TRX (16.25M energy).# (use your wallet or tronweb CLI)# 2. Sign the message {tx_hash}:{delegate_to} (proves you are the sender)# (use tronWeb.trx.signMessageV2 in your code)# 3. Claim delegation with tx hash + signature
curl -X POST https://api.tronnrg.com/delegate \
-H "Content-Type: application/json" \
-d '{
"tx_hash": "YOUR_PAYMENT_TX_HASH",
"delegate_to": "TWalletThatNeedsEnergy",
"signature": "YOUR_SIGNATURE"
}'# Response includes delegations[].tx — the on-chain hash you can verify on TronScan