DEVELOPER DOCS
ERROR CODES
Complete list of TronEnergy API error codes with descriptions and resolution steps.
Every error response has two fields: error (machine-readable, stable, never changes between versions) and message (human-readable, may be improved over time). Always switch on error in your code. Display message to users.
Error Format
All error responses follow the same structure:
error response
{
"error": "error_code_here",
"message": "Human-readable explanation"
}
Some errors include additional fields: ref (a reference ID for the delegation attempt) and refund (details about an automatic refund).
Validation Errors
| Error Code | HTTP | Cause | Resolution |
|---|---|---|---|
invalid_tx_hash | 400 | tx_hash is not a 64-character hex string | Check the hash format. Must be exactly 64 hex characters, no prefix. |
invalid_address | 400 | delegate_to is not a valid Tron address | Validate the address with TronWeb.isAddress() before calling. |
missing_signature | 400 | No signature provided in the request | Sign the message {tx_hash}:{delegate_to} with tronWeb.trx.signMessageV2() from the wallet that sent the TRX. |
invalid_signature | 401 | Signature could not be verified | Ensure you signed exactly {tx_hash}:{delegate_to} (lowercase hex hash, colon, exact Tron address). |
signature_mismatch | 403 | Signer address does not match the payment sender | The signature must come from the same wallet that sent the TRX payment. Different wallet = rejected. |
Payment Errors
| Error Code | HTTP | Cause | Resolution |
|---|---|---|---|
payment_verification_failed | 404 / 400 | The on-chain payment could not be verified. The message field describes the specific cause. | Common causes: tx not yet confirmed (wait 3-5 seconds and retry once), wrong recipient address, transaction is not a TRX transfer, below the 4 TRX minimum. |
hash_already_used | 409 | This tx hash has already been claimed | Each payment hash can only be used once. Send a new payment for a new delegation. |
Service Errors
| Error Code | HTTP | Cause | Resolution |
|---|---|---|---|
delegation_failed | 400 / 500 | Provider could not deliver the energy delegation | If the failure happened after your payment was verified, an automatic refund is queued. Check the refund object. Otherwise retry, or contact support with the ref ID. |
rate_limited | 429 | Too many requests from this IP | Slow down and retry. Limit is 20 requests per second. |
server_error | 500 | Unexpected internal error | Retry after a few seconds. If persistent, contact support with the ref if available. |
Handling Errors in Code
recommended error handling
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);