डेवलपर दस्तावेज़
TronEnergy API त्रुटि कोड और समस्या निवारण
TronEnergy API त्रुटि कोड की संपूर्ण सूची विवरण, कारण और समाधान चरणों के साथ। भुगतान सत्यापन, हस्ताक्षर और delegation त्रुटियों को कवर करता है।
प्रत्येक त्रुटि प्रतिक्रिया में दो फ़ील्ड हैं: error (machine-readable, स्थिर, संस्करणों के बीच कभी नहीं बदलता है) और message (human-readable, समय के साथ सुधार किया जा सकता है)। हमेशा अपने कोड में error पर स्विच करें। message को उपयोगकर्ताओं को प्रदर्शित करें।
त्रुटि प्रारूप
सभी त्रुटि प्रतिक्रियाएं एक ही संरचना का पालन करती हैं:
त्रुटि प्रतिक्रिया
{
"error": "error_code_here",
"message": "Human-readable explanation"
}
कुछ त्रुटियों में अतिरिक्त फील्ड होते हैं: ref (delegation attempt के लिए एक reference ID) और refund (automatic refund के बारे में विवरण)।
Validation Errors
| Error Code | HTTP | कारण | समाधान |
|---|---|---|---|
invalid_tx_hash | 400 | tx_hash 64-character hex string नहीं है | hash format को check करें। बिल्कुल 64 hex characters होने चाहिए, कोई prefix नहीं। |
invalid_address | 400 | delegate_to एक valid Tron address नहीं है | call करने से पहले TronWeb.isAddress() से address को validate करें। |
missing_signature | 400 | request में कोई signature प्रदान नहीं किया गया | message को sign करें {tx_hash}:{delegate_to} के साथ tronWeb.trx.signMessageV2() उस wallet से जिसने TRX भेजा है। |
invalid_signature | 401 | Signature को verify नहीं किया जा सका | सुनिश्चित करें कि आपने बिल्कुल {tx_hash}:{delegate_to} (lowercase hex hash, colon, exact Tron address) को sign किया है। |
signature_mismatch | 403 | Signer address payment भेजने वाले से मेल नहीं खाता | Signature उसी wallet से आना चाहिए जिसने TRX payment भेजा है। अलग wallet = rejected। |
Payment Errors
| Error Code | HTTP | कारण | समाधान |
|---|---|---|---|
payment_verification_failed | 404 / 400 | on-chain payment को verify नहीं किया जा सका। message field specific कारण बताता है। | आम कारण: tx अभी confirmed नहीं हुआ है (3-5 seconds प्रतीक्षा करें और फिर से retry करें), गलत recipient address, transaction एक TRX transfer नहीं है, 4 TRX minimum से कम है। |
hash_already_used | 409 | इस tx hash को पहले ही claim किया जा चुका है | प्रत्येक payment hash को केवल एक बार use किया जा सकता है। नए delegation के लिए नया payment भेजें। |
Service Errors
| Error Code | HTTP | कारण | समाधान |
|---|---|---|---|
delegation_failed | 400 / 500 | Provider energy delegation deliver नहीं कर सका | अगर failure आपके payment verify होने के बाद हुई है, तो एक automatic refund queue में है। check करें refund ऑब्जेक्ट। अन्यथा दोबारा कोशिश करें, या support से संपर्क करें ref ID। |
rate_limited | 429 | इस IP से बहुत सारे अनुरोध | गति कम करें और दोबारा कोशिश करें। सीमा 20 अनुरोध प्रति सेकंड है। |
server_error | 500 | अप्रत्याशित आंतरिक त्रुटि | कुछ सेकंड के बाद दोबारा कोशिश करें। यदि समस्या बनी रहे, तो support से संपर्क करें ref यदि उपलब्ध हो। |
कोड में त्रुटियों को संभालना
अनुशंसित त्रुटि हैंडलिंग
const result = await fetch('https://api.tronnrg.com/delegate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ tx_hash: hash, delegate_to: addr, signature: sig }),
}).then(r => r.json());
if (result.error) {
switch (result.error) {
case 'payment_verification_failed':
// Most common: tx not yet indexed. Wait 3s and retry once.
await new Promise(r => setTimeout(r, 3000));
return retry(hash, addr);
case 'hash_already_used':
// Already claimed. Don't retry.
throw new Error('Duplicate delegation attempt');
case 'signature_mismatch':
// Signer != payment sender. Sign with the same key.
throw new Error('Signer does not match payment sender');
case 'delegation_failed':
// Refund queued automatically if payment was verified.
if (result.refund) console.log('Refund queued:', result.refund);
break;
default:
console.error(result.error, result.message);
}
return;
}
// Success
console.log('Delegated:', result.energy, 'energy');
console.log('Delegation tx:', result.delegations[0].tx); // verify on TronScan
console.log('Ref:', result.ref);