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 CodeHTTPCauseResolution
invalid_tx_hash400tx_hash is not a 64-character hex stringCheck the hash format. Must be exactly 64 hex characters, no prefix.
invalid_address400delegate_to is not a valid Tron addressValidate the address with TronWeb.isAddress() before calling.
missing_signature400No signature provided in the requestSign the message {tx_hash}:{delegate_to} with tronWeb.trx.signMessageV2() from the wallet that sent the TRX.
invalid_signature401Signature could not be verifiedEnsure you signed exactly {tx_hash}:{delegate_to} (lowercase hex hash, colon, exact Tron address).
signature_mismatch403Signer address does not match the payment senderThe signature must come from the same wallet that sent the TRX payment. Different wallet = rejected.

Payment Errors

Error CodeHTTPCauseResolution
payment_verification_failed404 / 400The 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_used409This tx hash has already been claimedEach payment hash can only be used once. Send a new payment for a new delegation.

Service Errors

Error CodeHTTPCauseResolution
delegation_failed400 / 500Provider could not deliver the energy delegationIf 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_limited429Too many requests from this IPSlow down and retry. Limit is 20 requests per second.
server_error500Unexpected internal errorRetry 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);
Telegram WhatsApp