This repository demonstrates how to develop, test, and deploy TRON smart contracts using TronBox and GitHub Actions for continuous integration and deployment (CI/CD). The project includes:
-
A sample Solidity contract (
SimpleStorage.sol) -
Migration scripts for deployment
-
Unit tests using the TronBox framework
-
A GitHub Actions workflow to automatically:
- Install dependencies
- Compile and test the contracts on the Nile testnet
- Deploy the contracts to Nile if tests pass
- Smart Contract Development: Write, compile, and test TRON contracts in Solidity using TronBox.
- Automated Testing: Every push or pull request to
maintriggers a workflow that runs the test suite. - Continuous Deployment: Successful tests automatically trigger deployment to the TRON Nile network.
- Secure Secrets: Private keys and node URLs are stored as GitHub Secrets and passed as environment variables.
- Security Analysis: Integrates Slither static analyzer for Solidity smart contracts.
- Node.js (v20 or higher recommended)
- TronBox globally or as a dev dependency (installed via
npm installin this project) - Git for version control
- Slither analyzer installed (
pip install slither-analyzer) - A GitHub repository with Actions enabled
tronbox-CICD
├── contracts/
│ ├── SimpleStorage.sol # Example Solidity contract
│ ├── Migrations.sol # Example Migration contract
├── migrations/
│ ├── 1_initial_migration.js # Tracks TronBox migrations
│ ├── 2_deploy_contracts.js # Deploy script for SimpleStorage
├── test/
│ └── SimpleStorage.test.js # Example tests
├── tronbox.js # TronBox config (network definitions)
├── package.json # Node dependencies & scripts
└── .github/workflows/
└── tron.yml # GitHub Actions CI/CD pipelineClone the Repository
git clone https://github.com/aziz1975/tronbox-CICD.git
cd tronbox-CICDInstall Dependencies
npm installCompile Contracts
npx tronbox compileBy default, if you run npx tronbox test, it uses the development network in tronbox.js (if defined). To explicitly use Nile (if you’ve configured it and provided environment variables locally), run:
npx tronbox test --network nilenpx tronbox deploy --network nileThis repository uses GitHub Actions to automate the build, test, and deployment processes for Tron smart contracts. The workflow is defined in the .github/workflows/tron.yml file.
- Push to
mainbranch - Pull requests targeting the
mainbranch
- Checkout the code
- Set up Node.js (version 20)
- Install dependencies
- Compile contracts
- Run tests against Nile testnet (requires GitHub secrets)
- Upload artifacts
- Download artifacts
- Set up Node.js
- Deploy contracts to Nile
To enhance the security and quality of your smart contracts, this project integrates Slither—a Solidity static analysis tool.
Install Slither globally or within your virtual environment:
pip install slither-analyzerTo analyze your contracts, run:
slither contracts/SimpleStorage.solSlither outputs detailed reports highlighting potential vulnerabilities, coding mistakes, and optimization suggestions.
Add the following step in your tron.yml workflow to automate Slither analysis:
- name: Run Slither static analysis
run: |
pip install slither-analyzer
slither contracts/If you encounter the ‘ERROR: No contract or not a valid smart contract’ message in the GitHub Actions logs, simply rerun the jobs. Occasionally, a network glitch causes this error.
To securely handle sensitive data, set the following secrets in your GitHub repository:
-
Go to your repository’s Settings.
-
Click on Secrets and variables > Actions.
-
Add the following secrets:
PRIVATE_KEY_NILE: Private key for Nile testnet.FULL_NODE_NILE: URL of the Nile testnet node (https://nile.trongrid.io).
- Multiple Deployments: The pipeline deploys contracts once during testing and again in the deploy job. Consider using local networks for tests to avoid multiple Nile deployments.
- Verification: Verify deployments via Nile’s block explorer.
Feel free to open issues or submit pull requests for improvements or bug fixes. Ensure changes are thoroughly tested and documented.