Tron Energy Rental API Reference: REST Endpoints & Integration
TronEnergy Energy delegation के लिए complete REST API documentation। POST /delegate endpoint, HMAC authentication, request/response formats, error codes, और rate limits।
Base URL:https://api.tronnrg.comAuth: कोई requirement नहीं। सभी endpoints public हैं।
Rate limit: प्रति IP 20 requests/second
Payment address:TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx (केवल API के लिए, manual rentals के लिए नहीं)
यह कैसे काम करता है
तीन steps। कोई API key नहीं, कोई sign-up नहीं, कोई wallet connection नहीं। Ownership को cryptographically prove किया जाता है।
Sign करें — Message को {tx_hash}:{delegate_to} से sign करें जिस wallet ने TRX भेजा है। यह साबित करता है कि आपने delegation को authorize किया है।
Claim करें — POST /delegate के साथ tx_hash, delegate_to, और signature। Energy ~3 सेकंड में आ जाती है।
Payment Address
TFqUiCu1JwLHHnBNeaaVKH7Csm4aA3YhZx
केवल API payment address। यह address API के माध्यम से programmatic integrations के लिए है। इसे manual energy rentals के लिए उपयोग न करें। Manual rental address अलग है और पर उपलब्ध है।tronnrg.com.
इस address पर TRX भेजें। आपके payment का transaction hash आपका delegation को trigger करने का token है। प्रत्येक hash को केवल एक बार उपयोग किया जा सकता है।
भेजा गया TRX
Delegated Energy
Use Case
4 TRX
65,000
मौजूदा wallet को standard USDT transfer (न्यूनतम order)
8 TRX
130,000
पहली बार recipient को USDT transfer
16 TRX
260,000
एक order में चार standard transfers
40 TRX
650,000
दस standard transfers
100 TRX
1,625,000
~25 standard transfers — छोटे platforms के लिए आम
1,000 TRX
16,250,000
अधिकतम order, ~250 standard transfers
इसके बीच कोई भी amount
trx × 16,250
पूरी तरह linear। कोई tiers नहीं, कोई packages नहीं, कोई discounts नहीं।
Formula:energy = trxSent × 16,250. Bounds: न्यूनतम 4 TRX (65,000 energy), अधिकतम 1,000 TRX (16,250,000 energy)। दोनों API level पर enforce किए जाते हैं — न्यूनतम से नीचे की amounts को below_minimum के साथ reject और refund किया जाता है; अधिकतम से ऊपर की amounts को delegation से पहले reject किया जाता है।
POST /delegate
POST/delegate
एक energy delegation प्राप्त करें। आपको पहले से ही on-chain payment address पर TRX भेज चुका होना चाहिए। Transaction hash, recipient address, और एक signature pass करें जो साबित करता है कि आप sender हैं।
पैरामीटर
प्रकार
विवरण
tx_hash
string
आवश्यक
TRX payment का 64-character hex hash
delegate_to
string
आवश्यक
Tron address जो energy प्राप्त करेगा
signature
string
आवश्यक
tronWeb.trx.signMessageV2() of tronWeb.trx.signMessageV2()। साबित करता है कि आप payment sender हैं।
TronNRG reference ID। Support queries के लिए इसे log करें।
energy
number
कुल energy delegated
cost
number
TRX charged
status
string
सफलता पर "delegated"
delegations
array
On-chain delegation transaction hashes। प्रत्येक tx को TronScan पर verify किया जा सकता है। यह आपकी receipt है।
GET /health
GET/health
Monitoring और uptime tools के लिए liveness check। 200 OK return करता है जब API process up हो। Upstream nodes या providers को check नहीं करता।
प्रतिक्रिया 200
{ "status": "ok" }
Error Codes
हर error response के पास error (stable, machine-readable) और message (human-readable) होता है। अपने code में हमेशा error पर switch करें।
कोड
HTTP
अर्थ
invalid_tx_hash
400
64-character hex string नहीं है
invalid_address
400
valid Tron address नहीं है
missing_signature
400
कोई signature प्रदान नहीं किया गया
invalid_signature
401
Signature को verify नहीं किया जा सका
signature_mismatch
403
Signer address payment sender से match नहीं करता
hash_already_used
409
Transaction hash पहले से claim किया जा चुका है
payment_verification_failed
404 / 400
Payment का on-chain verification विफल हो गया। विशिष्ट कारण के लिए message field को पढ़ें: tx अभी नहीं मिला (404, कुछ सेकंड में retry करें), गलत recipient, TRX transfer नहीं, या 4 TRX minimum से नीचे।
delegation_failed
400 / 500
Provider energy deliver नहीं कर सका। अगर failure payment verify होने के बाद हुई, तो refund automatically queued है। इस स्थिति में refund object को check करें।
rate_limited
429
इस IP से प्रति सेकंड बहुत सारे अनुरोध। सीमा 20/sec है।
server_error
500
अप्रत्याशित आंतरिक त्रुटि। कुछ सेकंड में दोबारा कोशिश करें।
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;
}
}
रिफंड
यदि आपके भुगतान की पुष्टि के बाद प्रतिनिधिमंडन विफल हो जाता है, तो TRX रिफंड स्वचालित रूप से कतार में आ जाता है और भेजने वाले पते को वापस भेज दिया जाता है। त्रुटि प्रतिक्रिया में रिफंड ऑब्जेक्ट देखें।
रिफंड के साथ त्रुटि
{
"error": "delegation_failed",
"message": "Energy delegation failed. Your payment will be refunded.",
"ref": "nrg_d_43",
"refund": {
"type": "queued",
"to": "TSenderAddress",
"amount": 4
}
}
संपूर्ण उदाहरण
पूर्ण end-to-end प्रवाह: TRX भेजें, हस्ताक्षर करें, दोबारा कोशिश के साथ क्लेम करें। कॉपी और चलाएं।
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