Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
Supported ChainsTRONTRON HTTP API

wallet/broadcasthex - Broadcast Raw Transaction...

Broadcast a signed TRON transaction in hexadecimal format to the network via Dwellir's high-performance RPC endpoint.

TRON RPC endpoint: endpoint URLs, plans and pricing.

Broadcast a signed transaction in hexadecimal format to the TRON network.

Endpoint

Text
POST /wallet/broadcasthex
cURL request
# Broadcast signed transaction hex
    curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/broadcasthex \
      -H "Content-Type: application/json" \
      -d '{
        "transaction": "0a85010a0227f02208c89fc99c0f53e5c940c8fbe4f62d5a67080112630a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412320a1541e552f6487911a8245ef73158f8eb5dd3343dc2121541d1e7a6bc354106cb410e65ff8b181c600ff1429218c0843d70f5bce4f62d124138cb1c9a31f44e0e929e44e3f6e4e33a056eb92e4e4c94db2e5892a2834ae0ed8010e1bd7bc5cf5fa100"
      }'

    # Check result with jq
    curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/broadcasthex \
      -H "Content-Type: application/json" \
      -d '{
        "transaction": "YOUR_SIGNED_TX_HEX"
      }' | jq '.result, .txid, .message'

Important Notes

Transaction Format

  1. Must be signed: Transaction must be properly signed before broadcasting
  2. Hex encoded: Entire signed transaction must be hex encoded
  3. Valid expiration: Transaction must not be expired
  4. Proper structure: Must follow TRON transaction format

Common Use Cases

  • Broadcasting pre-signed transactions
  • Offline transaction signing
  • Multi-signature transactions
  • Hardware wallet integrations

Implementation Examples

Error Codes

CodeDescriptionSolution
TRANSACTION_EXPIRATION_ERRORTransaction has expiredCreate new transaction with longer expiration
DUP_TRANSACTION_ERRORTransaction already broadcastTransaction already in mempool or confirmed
TAPOS_ERRORInvalid block referenceUpdate reference block in transaction
TOO_BIG_TRANSACTION_ERRORTransaction size too largeReduce transaction data size
TRANSACTION_SIGN_ERRORInvalid signatureVerify signature is correct
ACCOUNT_NOT_EXIST_ERRORAccount doesn't existEnsure account is activated
NOT_ENOUGH_BANDWIDTHInsufficient bandwidthStake TRX for bandwidth or burn TRX
NOT_ENOUGH_ENERGYInsufficient energyStake TRX for energy or burn TRX

Advanced Usage

JavaScript
class TransactionBroadcaster {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = `https://api-tron-mainnet.n.dwellir.com/${apiKey}`;
  }

  // Broadcast with retry logic
  async broadcastWithRetry(hexTx, maxRetries = 3) {
    let lastError;
    
    for (let i = 0; i < maxRetries; i++) {
      try {
        const response = await fetch(`${this.baseUrl}/wallet/broadcasthex`, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ transaction: hexTx })
        });
        
        const result = await response.json();
        
        if (result.result) {
          return {
            success: true,
            txid: result.txid,
            attempts: i + 1
          };
        }
        
        // Check if error is retryable
        if (result.code === 'DUP_TRANSACTION_ERROR') {
          // Transaction already broadcast, consider it success
          return {
            success: true,
            message: 'Transaction already broadcast',
            attempts: i + 1
          };
        }
        
        if (result.code === 'TRANSACTION_EXPIRATION_ERROR') {
          // Don't retry expired transactions
          throw new Error('Transaction expired, cannot retry');
        }
        
        lastError = result;
        
        // Wait before retry
        await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
        
      } catch (error) {
        lastError = error;
      }
    }
    
    return {
      success: false,
      error: lastError,
      attempts: maxRetries
    };
  }

  // Validate hex transaction before broadcasting
  validateHexTransaction(hexTx) {
    try {
      // Check if valid hex
      if (!/^[0-9a-fA-F]+$/.test(hexTx)) {
        return { valid: false, error: 'Invalid hex format' };
      }
      
      // Check minimum length (rough estimate)
      if (hexTx.length < 100) {
        return { valid: false, error: 'Transaction too short' };
      }
      
      // Check maximum length
      if (hexTx.length > 65536 * 2) { // 64KB in hex
        return { valid: false, error: 'Transaction too large' };
      }
      
      return { valid: true };
      
    } catch (error) {
      return { valid: false, error: error.message };
    }
  }

  // Batch broadcast multiple transactions
  async batchBroadcast(hexTransactions) {
    const results = [];
    
    for (const hexTx of hexTransactions) {
      // Validate before broadcasting
      const validation = this.validateHexTransaction(hexTx);
      
      if (!validation.valid) {
        results.push({
          success: false,
          error: validation.error
        });
        continue;
      }
      
      // Broadcast with retry
      const result = await this.broadcastWithRetry(hexTx);
      results.push(result);
      
      // Small delay between broadcasts
      await new Promise(resolve => setTimeout(resolve, 100));
    }
    
    return results;
  }
}

// Example usage
async function advancedBroadcast() {
  const broadcaster = new TransactionBroadcaster('YOUR_API_KEY');
  
  // Single transaction with retry
  const txHex = 'YOUR_SIGNED_TX_HEX';
  const result = await broadcaster.broadcastWithRetry(txHex);
  
  if (result.success) {
    console.log(`Transaction broadcast after ${result.attempts} attempts`);
    console.log(`TX ID: ${result.txid}`);
  } else {
    console.error('Broadcast failed:', result.error);
  }
  
  // Batch broadcast
  const transactions = [
    'SIGNED_TX_HEX_1',
    'SIGNED_TX_HEX_2',
    'SIGNED_TX_HEX_3'
  ];
  
  const batchResults = await broadcaster.batchBroadcast(transactions);
  
  batchResults.forEach((result, index) => {
    if (result.success) {
      console.log(`TX ${index + 1}: Success - ${result.txid}`);
    } else {
      console.log(`TX ${index + 1}: Failed - ${result.error}`);
    }
  });
}

Best Practices

1. Validation

  • Validate hex format before broadcasting
  • Check transaction expiration
  • Verify sufficient resources

2. Error Handling

  • Implement retry logic for network errors
  • Handle duplicate transaction errors gracefully
  • Log all broadcast attempts

3. Security

  • Never expose private keys
  • Use secure channels for hex transmission
  • Verify transaction details before broadcasting

4. Optimization

  • Batch transactions when possible
  • Monitor network congestion
  • Set appropriate expiration times

Use Cases

  • Offline Signing: Sign transactions on air-gapped devices
  • Multi-Signature: Collect signatures offline, broadcast online
  • Hardware Wallets: Integrate with Ledger, Trezor, etc.
  • Transaction Relaying: Relay pre-signed transactions
  • Automated Systems: Broadcast pre-prepared transactions

Related Methods

  • wallet/broadcasttransaction - Broadcast JSON transaction
  • wallet/gettransactionbyid - Check transaction status
  • wallet/gettransactioninfobyid - Get transaction receipt

wallet/broadcasttransaction

Broadcast signed TRON transactions to the network with instant confirmation and detailed result tracking via Dwellir's high-performance endpoints.

wallet/gettransactionbyid

Retrieve detailed TRON transaction information by transaction ID including status, fees, contracts executed, and block confirmation via Dwellir RPC.

On this page

EndpointImportant NotesTransaction FormatCommon Use CasesImplementation ExamplesError CodesAdvanced UsageBest Practices1. Validation2. Error Handling3. Security4. OptimizationUse CasesRelated Methods