Estimate
Quote what a relay will cost before you submit it.
Estimating is optional. Execute quotes again on its own, and Construct transaction returns an inline quote.
To show the current energy price without an API key, for example on a website, use Pricing.
Estimate a relay
Returns the cost of a relay. For the token fee modes it also returns the fee your user pays and where to send it. Limit: 30 per minute.
curl -X POST "https://apiv2.tronergy.io/api/chain_relayers/portal/estimate" \
-H "x-api-key: $TRONERGY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"chain": "tron",
"mode": "delegate_energy",
"payload": {
"target_address": "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8",
"token": "USDT",
"operation": "transfer"
},
"environment": "live"
}'chainstringrequiredAlways tron.
modestringrequireddelegate_energy, sponsored_broadcast, token_pay, trx_fee_token_pay or sunswap_swap.
payloadRecord<string, unknown>requiredDepends on mode, see the table below. Max 64 KB, must not be empty.
environment"sandbox" | "live"sandbox or live. Defaults to sandbox.
{
"ok": true,
"chain": "tron",
"mode": "delegate_energy",
"estimatedCostNative": "2.950000",
"estimatedCostUsd": "0.84000000",
"unit": "TRX",
"breakdown": { "energyAmount": 65000, "bandwidthAmount": 345, "recipientActivated": true }
}estimatedCostNative is what your balance is charged, in TRX. breakdown is for display only; its fields may change. Values are an example.
If the node shows that the transaction would revert as it stands (for example, the sender does not hold the tokens yet), you still get the quote, plus:
{ "simulation": { "reverted": true, "reason": "REVERT opcode executed" } }This is a warning, not an error, so you can quote before the wallet is funded. simulation is absent when the transaction simulated cleanly or could not be simulated. If you execute a transaction that still reverts, it is refused with 422 SIMULATION_REVERTED before anything is held or charged.
Payload by mode
| Mode | payload |
|---|---|
delegate_energy | { "target_address", "token": "USDT", "operation": "transfer" | "approve" } for a template quote, or { "target_address", "energy_amount" } for a fixed amount. |
sponsored_broadcast | { "signed_tx" }, the signed TronWeb transaction. Before signing: { "contract_address", "function_selector", "parameter", "user_address" }. |
token_pay, trx_fee_token_pay | { "fee_signed_tx", "user_signed_tx" }. Before signing: describe both calls, see below. |
sunswap_swap | A swap intent. See Swap. |
Quote before signing (token fee modes)
You need the fee before you build the fee transaction, so describe the calls instead of sending signed transactions:
{
"fee_contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"fee_function_selector": "transfer(address,uint256)",
"fee_parameter": [{ "type": "address", "value": "<any TRON address>" }, { "type": "uint256", "value": "1000000" }],
"fee_user_address": "TUser...",
"user_contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"user_function_selector": "transfer(address,uint256)",
"user_parameter": [{ "type": "address", "value": "TRecipient..." }, { "type": "uint256", "value": "25000000" }],
"user_user_address": "TUser..."
}For trx_fee_token_pay, replace the three fee_contract_address / fee_function_selector / fee_parameter fields with "fee_kind": "native_trx". For a payable user call, add "call_value" in sun.
The response then also has:
| Field | Mode | Meaning |
|---|---|---|
feeRecipient | both | Address the fee transaction must pay. |
feeTokenContract | token_pay | Token the fee is paid in. |
feeAmount | token_pay | Fee in the token's smallest unit ("1250000" = 1.25 USDT). |
feeAmountSun | trx_fee_token_pay | Fee in sun. |
Pass these to Construct transaction. Full flow: Pay fees in tokens.
A signed transaction must have at least 30 seconds left (sponsored_broadcast) or 45 seconds (token fee modes) before it expires, or you get TX_EXPIRED. execute needs 5 seconds more (35 and 50), and 38 seconds for a sponsored_broadcast whose energy comes from a marketplace provider when you also need bandwidth; it answers TX_EXPIRING_SOON with the exact number.
Common errors: 422 Validation failed, 422 INVALID_PAYLOAD, 400 TX_*, 422 PROVIDER_NOT_FOUND, 429. See Errors.
List supported modes
Returns the chains and relay modes enabled for your account. An empty providers list means relaying is not enabled yet.
{
"ok": true,
"providers": [
{
"providerKey": "tron",
"modes": [
{ "chain": "tron", "mode": "delegate_energy" },
{ "chain": "tron", "mode": "sponsored_broadcast" },
{ "chain": "tron", "mode": "token_pay" },
{ "chain": "tron", "mode": "trx_fee_token_pay" },
{ "chain": "tron", "mode": "sunswap_swap" }
]
}
]
}