TronBox: Smart Contract Development on TRON
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
npm install -g tronbox mkdir my-tron-dapp && cd my-tron-dapp tronbox init
Generated layout:
contracts/ # Solidity source migrations/ # Deployment scripts tronbox.js # Network config tronbox-config.js # Optional overrides
tronbox.js configuration
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:
const MyContract = artifacts.require('MyContract');
module.exports = function (deployer) {
deployer.deploy(MyContract, /* constructor args */);
};
Run:
tronbox compile tronbox migrate --network shasta
Reset local deployment state:
tronbox migrate --reset --network shasta
Testing
Options:
- Manual — TronIDE, TronScan read/write contract
- Scripts — TronWeb integration tests against Shasta
- TronBox console —
tronbox console --network shasta
Automated test ecosystem is thinner than Ethereum's — many teams use custom Jest + TronWeb scripts.
Shasta workflow
- Generate Shasta wallet (TronLink Shasta mode or
tronWeb.createAccount()) - Fund from Shasta faucet
- Migrate contracts
- Verify on Shasta TronScan
- Run TronWeb interaction scripts
Mainnet deployment checklist
- [ ] Audit or internal security review — smart contract security
- [ ] Constructor args double-checked
- [ ] Deployer wallet funded TRX + Energy
- [ ]
feeLimitsufficient for large contracts - [ ] Verify source on TronScan post-deploy
- [ ] Transfer ownership to multisig if applicable
tronbox migrate --network mainnet
TronBox vs TronIDE
| Tool | Best for |
|---|---|
| TronBox | Multi-contract projects, migrations, CI |
| TronIDE | Quick browser deploy, learning |
Many teams prototype in TronIDE, productionize in TronBox.
Common issues
| Issue | Fix |
|---|---|
| Compile version mismatch | Align solc in tronbox.js with pragma |
| OUT_OF_ENERGY on migrate | Increase feeLimit; freeze TRX on deployer |
| Network timeout | Add TronGrid API key |
| Wrong network_id | Match 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.
Related guides
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.
Thanks — your feedback helps us improve the docs.