Tronergydocs

Bring your own transaction

Build the transaction yourself with TronWeb and relay it with Tronergy.

You do not have to use construct-tx. If your app already builds TRON transactions, sign them as usual and send them to execute with sponsored_broadcast. Tronergy broadcasts them byte for byte.

Any smart-contract call or contract deploy works.

Build, sign, send

own-tx.ts
import { randomUUID } from 'node:crypto'
import { TronWeb } from 'tronweb'

const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io' })

const { transaction } = await tronWeb.transactionBuilder.triggerSmartContract(
  'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDT
  'transfer(address,uint256)',
  { feeLimit: 100_000_000 },
  [
    { type: 'address', value: 'TAbc...' },
    { type: 'uint256', value: '25000000' },
  ],
  'TXyz...', // sender
)

// TronWeb transactions live 60 seconds by default. Give it more time.
const extended = await tronWeb.transactionBuilder.extendExpiration(transaction, 300)
const signedTx = await tronWeb.trx.sign(extended, process.env.SENDER_PRIVATE_KEY!)

const res = await fetch('https://apiv2.tronergy.io/api/chain_relayers/portal/execute', {
  method: 'POST',
  headers: { 'content-type': 'application/json', 'x-api-key': process.env.TRONERGY_API_KEY! },
  body: JSON.stringify({
    chain: 'tron',
    mode: 'sponsored_broadcast',
    environment: 'live',
    idempotencyKey: randomUUID(),
    payload: { signed_tx: signedTx },
  }),
})

execute needs at least 35 seconds of life left on the transaction, and 38 seconds when the energy comes from a marketplace provider and your account also needs bandwidth, because we first prove the energy reached your account. A default TronWeb transaction lives 60 seconds; if it waits in the wallet or on the network, it can arrive with too little left. Always extend the expiration before signing (5 minutes is safe), or you get TX_EXPIRED or TX_EXPIRING_SOON.

Price it first

Already have a signed transaction? Send it to estimate with payload: { signed_tx } to see the cost before you execute.

construct-tx or your own?

  • Use construct-tx for the fastest start. It sets a 5-minute expiry, returns the cost, and decodes the transfer so you can show it to the user.
  • Build your own when your wallet or SDK already builds transactions, or you deploy a contract.

Either way, sign the transaction and do not change it afterwards.