TronBox: Smart Contract Development on TRON — TRON Wiki

TronBox: Smart Contract Development on TRON

11 min read · ⌘K search

TronBox is the standard development framework for TRON smart contracts — compiling Solidity, running migrations, and deploying to Shasta or mainnet. If you have used Truffle on Ethereum, TronBox workflows will feel familiar.

This guide covers project setup, configuration, migrations, testing workflow, and integration with TronWeb.

Install and init

Code
npm install -g tronbox
mkdir my-tron-dapp && cd my-tron-dapp
tronbox init

Generated layout:

Code
contracts/          # Solidity source
migrations/         # Deployment scripts
tronbox.js          # Network config
tronbox-config.js   # Optional overrides

tronbox.js configuration

Code
module.exports = {
  networks: {
    shasta: {
      privateKey: process.env.SHASTA_PRIVATE_KEY,
      userFeePercentage: 100,
      feeLimit: 1_000_000_000,
      fullHost: 'https://api.shasta.trongrid.io',
      network_id: '2',
    },
    mainnet: {
      privateKey: process.env.MAINNET_PRIVATE_KEY,
      userFeePercentage: 100,
      feeLimit: 1_000_000_000,
      fullHost: 'https://api.trongrid.io',
      headers: { 'TRON-PRO-API-KEY': process.env.TRONGRID_KEY },
      network_id: '1',
    },
  },
  compilers: {
    solc: {
      version: '0.8.20',
    },
  },
};

Never commit private keys — use environment variables.

Writing contracts

Solidity for TRON targets TVM. Example TRC-20 in deploy TRC-20 guide.

OpenZeppelin contracts work with version alignment — import via npm and configure solc remappings if needed.

Migrations

migrations/1_initial_migration.js — deploys Migrations tracker contract.

migrations/2_deploy_mycontract.js:

Code
const MyContract = artifacts.require('MyContract');

module.exports = function (deployer) {
  deployer.deploy(MyContract, /* constructor args */);
};

Run:

Code
tronbox compile
tronbox migrate --network shasta

Reset local deployment state:

Code
tronbox migrate --reset --network shasta

Testing

Options:

  • Manual — TronIDE, TronScan read/write contract
  • Scripts — TronWeb integration tests against Shasta
  • TronBox consoletronbox console --network shasta

Automated test ecosystem is thinner than Ethereum's — many teams use custom Jest + TronWeb scripts.

Shasta workflow

  1. Generate Shasta wallet (TronLink Shasta mode or tronWeb.createAccount())
  2. Fund from Shasta faucet
  3. Migrate contracts
  4. Verify on Shasta TronScan
  5. Run TronWeb interaction scripts

Mainnet deployment checklist

  • [ ] Audit or internal security review — smart contract security
  • [ ] Constructor args double-checked
  • [ ] Deployer wallet funded TRX + Energy
  • [ ] feeLimit sufficient for large contracts
  • [ ] Verify source on TronScan post-deploy
  • [ ] Transfer ownership to multisig if applicable
Code
tronbox migrate --network mainnet

TronBox vs TronIDE

ToolBest for
TronBoxMulti-contract projects, migrations, CI
TronIDEQuick browser deploy, learning

Many teams prototype in TronIDE, productionize in TronBox.

Common issues

IssueFix
Compile version mismatchAlign solc in tronbox.js with pragma
OUT_OF_ENERGY on migrateIncrease feeLimit; freeze TRX on deployer
Network timeoutAdd TronGrid API key
Wrong network_idMatch mainnet '1' / shasta '2'

Migration from TronBox to Hardhat

Some teams migrate to Hardhat with TRON plugins for unified Ethereum+TRON CI. TronBox remains valid for Solidity 0.5.x/0.8.x TRON deployments. Pick one toolchain per repo to avoid config drift.

Network configuration in tronbox.js

Define mainnet, shasta, and development networks with correct fullHost and privateKey from environment. Accidental mainnet deploy with test keys or vice versa causes incidents. Add pre-deploy confirmation script that prints network name and requires explicit CONFIRM=mainnet env var.

FAQ

What is TronBox?

TronBox is a development framework for TRON smart contracts — similar to Truffle on Ethereum — with compile, migrate, and network configuration.

Can TronBox deploy to mainnet?

Yes, with a funded private key in network config. Always test on Shasta testnet first.

Does TronBox support TypeScript migrations?

Migrations are JavaScript by default. You can use ts-node with custom setup or compile TS to JS.

How do I verify contracts deployed by TronBox?

Use TronScan verify UI with exact solc version and optimization settings from tronbox.js.

TronBox still maintained?

Check official TRON GitHub for latest releases. Pin versions in production CI.