TronBox
TronBox is an open-source development framework and testing environment designed for smart contracts built on the TRON Virtual Machine (TVM). Currently stable at version 4.6.0, it follows a periodic release cadence, incorporating updates for Solidity compiler support, underlying dependency upgrades like `tronweb` and `ethers`, and framework enhancements. As a direct fork of the popular Ethereum development suite Truffle, TronBox provides a familiar and robust toolkit for TRON developers, offering features such as built-in contract compilation, linking, deployment, binary management, an external script runner, an interactive console, automated contract testing, and a scriptable migration framework. Its key differentiator is its specialized focus on the TRON ecosystem, adapting Truffle's established workflows and tools to the specifics of TRON blockchain development, including seamless integration with `tronweb` and support for TRON-specific network configurations.
Common errors
-
'tronbox' is not recognized as an internal or external command, operable program or batch file.
cause TronBox CLI is not globally installed or not in the system's PATH.fixEnsure TronBox is installed globally using `npm install -g tronbox`. If already installed, verify your system's PATH environment variable. -
Error: Node.js vXX.YY.Z is not supported. TronBox requires Node.js >=20.0.0.
cause The installed Node.js version is older than the minimum required by TronBox.fixUpgrade your Node.js installation to version 20.0.0 or higher. Using a version manager like `nvm` (Node Version Manager) is recommended: `nvm install 20 && nvm use 20`. -
Error: Network 'development' not found in tronbox-config.js.
cause The specified network for compilation or migration is not defined in the `tronbox-config.js` file.fixOpen `tronbox-config.js` and add or correct the network configuration, ensuring the network name matches the one provided in the CLI command (e.g., `tronbox migrate --network myNetwork`).
Warnings
- breaking EPM (Ethereum Package Manager) support has been entirely removed from TronBox. Projects relying on EPM for package management will need to migrate to alternative dependency management solutions.
- breaking Configuration directory paths, including `build_directory`, `contracts_directory`, `contracts_build_directory`, `migrations_directory`, and `test_directory`, have been reconfigured. Existing projects may require updates to their `tronbox-config.js`.
- breaking TronBox has migrated from `web3` v4 to `ethers` v6 for all EVM-mode operations. This affects migration scripts, test scripts, and the TronBox console, requiring code adjustments for existing projects.
- breaking The `build`, `serve`, and `watch` CLI commands have been removed. These functionalities are no longer available directly via the TronBox CLI.
Install
-
npm install tronbox -
yarn add tronbox -
pnpm add tronbox
Imports
- tronbox CLI
import { tronbox } from 'tronbox'npm install -g tronbox tronbox <command>
- tronbox init
const project = new TronBoxProject()
tronbox init
- tronbox console
import { console } from 'tronbox'tronbox console
Quickstart
npm install -g tronbox
mkdir my-tron-project
cd my-tron-project
tronbox init
# Example contract in contracts/MyContract.sol (create this file)
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
contract MyContract {
string public greeting;
constructor() {
greeting = "Hello, TronBox!";
}
function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
# Example migration in migrations/1_deploy_my_contract.js (create this file)
const MyContract = artifacts.require("MyContract");
module.exports = function (deployer) {
deployer.deploy(MyContract);
};
tronbox compile
tronbox migrate --network development # Assuming 'development' network is configured in tronbox-config.js
tronbox test # Ensure test files exist in test/ directory
tronbox console