Base URL: https://api.tronnrg.com
Auth: ไม่จำเป็นต้องมี ปลายทางทั้งหมดเป็นแบบสาธารณะ
ขีดจำกัดอัตรา: 20 requests/second ต่อ IP
ที่อยู่การชำระเงิน: TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx (API เท่านั้น ไม่ใช่สำหรับการเช่าแบบ手動)
วิธีการทำงาน
สามขั้นตอน ไม่ต้องใช้คีย์ API ไม่ต้องลงทะเบียน ไม่ต้องเชื่อมต่อกระเป๋าเงิน การเป็นเจ้าของจะได้รับการพิสูจน์โดยการเข้ารหัส
ส่ง TRX — ส่ง TRX 4 ฟรี (หรือมากกว่า) ไปยังที่อยู่ชำระเงิน TRX 4 ฟรี = พลังงาน 65,000 TRX 8 ฟรี = พลังงาน 130,000 เป็นเชิงเส้น
ลงนาม — ลงนามข้อความ {tx_hash}:{delegate_to} โดยใช้กระเป๋าเงินที่ส่ง TRX นี่พิสูจน์ว่าคุณอนุมัติการมอบหมายพลังงาน
เรียกร้อง — POST /delegate พร้อมด้วย tx_hash, delegate_to และ signature พลังงานมาถึงในเวลาประมาณ 3 วินาที
ที่อยู่ชำระเงิน
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
คัดลอก
ที่อยู่ API ชำระเงินเท่านั้น ที่อยู่นี้สำหรับการรวมตัวโปรแกรมผ่าน API อย่าใช้สำหรับการเช่าพลังงานด้วยตนเอง ที่อยู่การเช่าด้วยตนเองนั้นแตกต่างและมีให้บริการบน
tronnrg.com .
ส่ง TRX ไปยังที่อยู่นี้ แฮชธุรกรรมของการชำระเงินของคุณคือโทเค็นของคุณเพื่อเริ่มการมอบหมายพลังงาน แต่ละแฮชสามารถใช้ได้เพียงครั้งเดียว
TRX ส่ง พลังงานมอบหมาย กรณีการใช้งาน
4 TRX 65,000 การโอน USDT มาตรฐานไปยังกระเป๋าเงินที่มีอยู่ (คำสั่งซื้อขั้นต่ำ)
8 TRX 130,000 การโอน USDT ไปยังผู้รับเป็นครั้งแรก
16 TRX 260,000 โอน USDT มาตรฐานสี่ครั้งในคำสั่งซื้อเดียว
40 TRX 650,000 การโอน USDT มาตรฐานสิบครั้ง
100 TRX 1,625,000 การโอน USDT มาตรฐานประมาณ 25 ครั้ง — ปกติสำหรับแพลตฟอร์มขนาดเล็ก
1,000 TRX 16,250,000 คำสั่งซื้อสูงสุด ประมาณการโอน USDT มาตรฐาน 250 ครั้ง
จำนวนใดก็ตามระหว่างนี้ trx × 16,250เป็นเชิงเส้นอย่างสมบูรณ์ ไม่มีชั้น ไม่มีแพคเกจ ไม่มีส่วนลด
สูตร: energy = trxSent × 16,250. ขอบเขต: ขั้นต่ำ TRX 4 ฟรี (พลังงาน 65,000) สูงสุด TRX 1,000 (พลังงาน 16,250,000) ทั้งสองจำกัดไว้ที่ระดับ API — จำนวนต่ำกว่าขั้นต่ำจะถูกปฏิเสธด้วย below_minimum และคืนเงิน จำนวนสูงกว่าสูงสุดจะถูกปฏิเสธก่อนการมอบหมายพลังงาน
POST /delegate
ขอรับการมอบหมายพลังงาน คุณต้องส่ง TRX ไปยังที่อยู่การชำระเงินบนเชนแล้ว ส่งแฮชธุรกรรม ที่อยู่ผู้รับ และลายเซ็นที่พิสูจน์ว่าคุณเป็นผู้ส่ง
พารามิเตอร์ ประเภท รายละเอียด
tx_hash string จำเป็น แฮชฐานสิบหก 64 ตัวอักษรของการชำระเงิน TRX
delegate_to string จำเป็น ที่อยู่ Tron เพื่อรับพลังงาน
signature string จำเป็น tronWeb.trx.signMessageV2() ของ tronWeb.trx.signMessageV2() พิสูจน์ว่าคุณเป็นผู้ส่งการชำระเงิน
cURL
JavaScript
Python
PHP
C#
คัดลอก
curl -X POST https://api.tronnrg.com/delegate \
-H "Content-Type: application/json" \
-d '{"tx_hash":"TX_HASH","delegate_to":"TWallet","signature":"SIG"}'
const result = await fetch ('https://api.tronnrg.com/delegate' , {
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' },
body : JSON .stringify ({
tx_hash : 'YOUR_TX_HASH' ,
delegate_to : 'TWalletAddress' ,
signature : 'YOUR_SIGNATURE' ,
}),
}).then (r => r.json ());
if (result.error) {
console.error (result.error, result.message);
} else {
console.log ('Delegated:' , result.energy, 'energy' );
console.log ('Ref:' , result.ref);
}
import requests
response = requests.post ('https://api.tronnrg.com/delegate' , json={
'tx_hash' : 'YOUR_TX_HASH' ,
'delegate_to' : 'TWalletAddress' ,
'signature' : 'YOUR_SIGNATURE' ,
})
result = response.json ()
if 'error' in result:
print (f"Error: {result['error']} - {result['message']}" )
else :
print (f"Delegated: {result['energy']} energy" )
print (f"Delegation tx: {result['delegations'][0]['tx']}" )
print (f"Ref: {result['ref']}" )
$ch = curl_init ('https://api.tronnrg.com/delegate' );
curl_setopt_array ($ch , [
CURLOPT_POST => true ,
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_HTTPHEADER => ['Content-Type: application/json' ],
CURLOPT_POSTFIELDS => json_encode ([
'tx_hash' => 'YOUR_TX_HASH' ,
'delegate_to' => 'TWalletAddress' ,
'signature' => 'YOUR_SIGNATURE' ,
]),
]);
$result = json_decode (curl_exec ($ch ), true );
curl_close ($ch );
if (isset ($result ['error' ])) {
echo "Error: " . $result ['message' ];
} else {
echo "Delegated: " . $result ['energy' ] . " energy" ;
}
var client = new HttpClient ();
var content = new StringContent (
JsonSerializer .Serialize (new {
tx_hash = "YOUR_TX_HASH" ,
delegate_to = "TWalletAddress" ,
signature = "YOUR_SIGNATURE"
}),
Encoding .UTF8, "application/json"
);
var response = await client.PostAsync ("https://api.tronnrg.com/delegate" , content);
var json = await response.Content.ReadAsStringAsync ();
var result = JsonSerializer .Deserialize <JsonElement >(json);
if (result.TryGetProperty ("error" , out var err))
Console .WriteLine ($"Error: {err}" );
else
Console .WriteLine ($"Delegated: {result.GetProperty("energy")} energy" );
{
"ref" : "nrg_d_42" ,
"delegate_to" : "TWalletAddress" ,
"energy" : 65000 ,
"cost" : 4 ,
"status" : "delegated" ,
"delegations" : [
{ "tx" : "a1b2c3d4e5f6...your delegation tx hash" , "energy" : 65000 }
]
}
ฟิลด์ ประเภท รายละเอียด
ref string รหัสอ้างอิง TronNRG บันทึกสิ่งนี้เพื่อการสอบถามด้านการสนับสนุน
energy number พลังงานทั้งหมดที่มอบหมาย
cost number TRX ที่เรียกเก็บ
status string "delegated" เมื่อสำเร็จ
delegations array แฮชธุรกรรมการมอบหมายบนเชน แต่ละรายการ tx สามารถตรวจสอบได้บน TronScan นี่คือใบเสร็จของคุณ
GET /health
การตรวจสอบความพร้อมใช้งานสำหรับเครื่องมือการตรวจสอบและเวลาทำงาน ส่งคืน 200 OK เมื่อกระบวนการ API ทำงานอยู่ ไม่ตรวจสอบโหนดหรือผู้ให้บริการต้นน้ำ
รหัสข้อผิดพลาด
ทุกการตอบสนองข้อผิดพลาดมี error (เสถียร อ่านได้โดยเครื่อง) และ message (อ่านได้โดยมนุษย์) เสมอให้สลับกับ error ในรหัสของคุณ
โค้ด HTTP ความหมาย
invalid_tx_hash400 ไม่ใช่สตริงฐานสิบหก 64 ตัวอักษร
invalid_address400 ไม่ใช่ที่อยู่ Tron ที่ถูกต้อง
missing_signature400 ไม่มีลายเซ็น
invalid_signature401 ไม่สามารถยืนยันลายเซ็น
signature_mismatch403 ที่อยู่ผู้ลงนามไม่ตรงกับผู้ส่งการชำระเงิน
hash_already_used409 แฮชธุรกรรมถูกอ้างสิทธิแล้ว
payment_verification_failed404 / 400 การตรวจสอบการชำระเงินบนเชนล้มเหลว อ่านฟิลด์ message เพื่อหาสาเหตุเฉพาะ: ไม่พบธุรกรรม (404 ลองใหม่ในไม่กี่วินาที) ผู้รับผิด ไม่ใช่การโอน TRX หรือต่ำกว่าขั้นต่ำ 4 TRX
delegation_failed400 / 500 ผู้ให้บริการไม่สามารถส่งมอบพลังงาน หากความล้มเหลวเกิดขึ้นหลังจากการตรวจสอบการชำระเงิน จะเข้าคิวเงินคืนโดยอัตโนมัติ ตรวจสอบ refund วัตถุเมื่อสิ่งนี้เกิดขึ้น
rate_limited429 มีการขอข้อมูลจำนวนมากเกินไปต่อวินาทีจาก IP นี้ ขีดจำกัดคือ 20/วินาที
server_error500 เกิดข้อผิดพลาดภายในที่ไม่คาดคิด ลองใหม่ในไม่กี่วินาที
JavaScript
Python
PHP
คัดลอก
const result = await fetch ('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.
pass
elif result['error' ] == 'hash_already_used' :
# Already claimed. Don't retry.
pass
elif result['error' ] == 'signature_mismatch' :
# Signer != payment sender. Sign with the same key.
pass
elif 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 ;
}
}
การคืนเงิน
หากการมอบหมายพลังงานล้มเหลวหลังจากยืนยันการชำระเงินแล้ว การคืน TRX จะถูกจัดคิวโดยอัตโนมัติและส่งกลับไปยังที่อยู่ผู้ส่งบน blockchain คุณจะเห็นออบเจกต์การคืนเงินในการตอบกลับข้อผิดพลาด
{
"error" : "delegation_failed" ,
"message" : "Energy delegation failed. Your payment will be refunded." ,
"ref" : "nrg_d_43" ,
"refund" : {
"type" : "queued" ,
"to" : "TSenderAddress" ,
"amount" : 4
}
}
ตัวอย่างที่สมบูรณ์
การไหลแบบปลายต่อปลายที่สมบูรณ์: ส่ง TRX ลงนาม ขอเรียกร้องพร้อมการลองใหม่ คัดลอกและเรียกใช้
JavaScript
Python
PHP
cURL
คัดลอก
const API = 'https://api.tronnrg.com' ;
const ADDR = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx' ;
async function rentEnergy (delegateTo, trxAmount = 4 ) {
// 1. Send TRX to the payment address
const payment = await tronWeb.trx.sendTransaction (ADDR, trxAmount * 1e6 );
// 2. Sign: proves you are the sender
const 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 = await fetch (`${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 new Error (result.message);
await new Promise (r => setTimeout (r, 3000 ));
}
if (result.error) throw new Error (result.message);
return result;
}
// Usage — send any amount between 4 and 1,000 TRX
const result = await rentEnergy ('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'
def rent_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 in range (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' :
raise Exception (result['message' ])
time.sleep (3 )
raise Exception ('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']}" )
<?php
$api = 'https://api.tronnrg.com' ;
$addr = 'TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx' ;
function rentEnergy ($api , $txHash , $delegateTo , $signature ) {
// 1. Send TRX to $addr (via iexbase/tron-api)
// $payment = $tron->sendTrx($addr, 4);
// $txHash = $payment['txid'];
// 3. Claim delegation (retry if tx not indexed yet)
for ($i = 0 ; $i < 3 ; $i ++) {
$ch = curl_init ("${api}/delegate" );
curl_setopt_array ($ch , [
CURLOPT_POST => true ,
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_HTTPHEADER => ['Content-Type: application/json' ],
CURLOPT_POSTFIELDS => json_encode ([
'tx_hash' => $txHash ,
'delegate_to' => $delegateTo ,
'signature' => $signature ,
]),
]);
$result = json_decode (curl_exec ($ch ), true );
curl_close ($ch );
if (!isset ($result ['error' ])) return $result ;
if ($result ['error' ] !== 'payment_verification_failed' )
throw new Exception ($result ['message' ]);
sleep (3 );
}
throw new Exception ('Transaction not found after retries' );
}
// Usage
$result = rentEnergy ($api , $txHash , 'TWalletThatNeedsEnergy' );
echo "Delegated: " . $result ['energy' ] . " energy\n" ;
echo "Delegation tx: " . $result ['delegations' ][0 ]['tx' ] . "\n" ;
echo "Ref: " . $result ['ref' ] . "\n" ;
# 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