Quickstart — deploy your first contract in 10 minutes
Deploy a Hello World smart contract on TRON in 10 minutes using TronBox CLI on the Shasta testnet.
Prerequisites
- Node.js 16+ and npm — TronBox runs on Node. Install from nodejs.org if you don't have it.
- A TRON account with Shasta testnet TRX — see Getting testnet tokens to fund a Shasta account.
- A code editor — VS Code or any editor of choice.
This quickstart deploys a Hello World contract on the Shasta testnet using TronBox CLI. The full path takes about 10 minutes.
Step 1 — Install TronBox
npm install -g tronbox
tronbox versionExpected output (any recent 4.x version):
Tronbox v4.3.0
Solidity v0.8.6 (solc-js)
Node v18.x.x
If you see command not found, your global npm bin directory is not on PATH. Run npm config get prefix to find it and add <prefix>/bin to your PATH.
Step 2 — Initialize a new project
mkdir hello-tron && cd hello-tron
tronbox initThis creates the standard TronBox project layout:
hello-tron/
├── contracts/
│ └── Migrations.sol ← required — manages migration state
├── migrations/
│ └── 1_initial_migration.js ← deploys Migrations.sol (auto-generated)
├── test/ ← test files
└── tronbox-config.js ← network and compiler config
Configuration file namingTronBox accepts both
tronbox.jsandtronbox-config.js. This guide usestronbox-config.jsbecause thetronbox.jsfilename can collide with thetronboxexecutable on Windows Command Prompt. Either filename works on macOS and Linux.
Step 3 — Write a Hello World contract
Create contracts/HelloWorld.sol:
pragma solidity 0.8.6;
contract HelloWorld {
string public message;
constructor(string memory initialMessage) {
message = initialMessage;
}
function setMessage(string memory newMessage) public {
message = newMessage;
}
}Create migrations/2_deploy_hello.js:
const HelloWorld = artifacts.require("HelloWorld");
module.exports = function (deployer) {
deployer.deploy(HelloWorld, "Hello, TRON!");
};Step 4 — Configure the Shasta network
Replace the contents of tronbox-config.js:
module.exports = {
networks: {
shasta: {
privateKey: process.env.PRIVATE_KEY,
userFeePercentage: 50,
feeLimit: 100 * 1e6, // 100 TRX, in sun
fullHost: 'https://api.shasta.trongrid.io',
network_id: '2'
}
},
compilers: {
solc: {
version: '0.8.6'
}
}
};
Never commit your private keyUse the
process.env.PRIVATE_KEYpattern shown above and set the value in your shell session, or use a.envfile plusdotenv. Hard-coding a key in source has caused many compromised mainnet accounts.
Step 5 — Compile
tronbox compileExpected output (truncated):
Compiling ./contracts/HelloWorld.sol...
Compiling ./contracts/Migrations.sol...
> Compiled successfully using:
- solc: 0.8.6+commit.11564f7e.Emscripten.clang
If the compiler reports a version error, ensure compilers.solc.version in tronbox-config.js matches your pragma solidity declaration.
Step 6 — Deploy to Shasta
export PRIVATE_KEY="your-private-key-without-0x-prefix"
tronbox migrate --network shastaExpected output (truncated):
Using network 'shasta'.
Running migration: 1_initial_migration.js
Deploying Migrations...
Migrations: TContractAddress...
Saving successful migration to network...
Saving artifacts...
Running migration: 2_deploy_hello.js
Deploying HelloWorld...
HelloWorld: TContractAddress...
Saving successful migration to network...
Saving artifacts...
Copy the HelloWorld contract address — you'll need it in the next step.
If deployment fails with Insufficient balance, the deployer account does not have enough TRX. Get Shasta testnet TRX from the Shasta faucet.
Step 7 — Call the contract from the console
tronbox console --network shastaThe console prompt shows the connected network:
tronbox(shasta)> let instance = await HelloWorld.deployed()
tronbox(shasta)> let msg = await instance.message()
tronbox(shasta)> console.log(msg)
'Hello, TRON!'
tronbox(shasta)> await instance.setMessage("Hello again!")
tronbox(shasta)> let updated = await instance.message()
tronbox(shasta)> console.log(updated)
'Hello again!'You've now deployed and called your first TRON smart contract.
Where to go next
- Understand the TVM — TVM concepts
- Learn the deployment lifecycle in depth — Development lifecycle
- Port an existing Ethereum contract — Migrating from Ethereum
- Cost optimization — FeeLimit & Energy cost
- Issue a token — TRC-20 or TRC-721
Common errors
| Error | Cause | Fix |
|---|---|---|
command not found: tronbox | TronBox not in PATH | Run npm install -g tronbox; add npm global bin to PATH |
Compiler version mismatch | pragma and tronbox-config.js differ | Set both to the same version |
Insufficient balance | Deployer has no TRX | Visit the Shasta faucet |
Network connection error | fullHost wrong / network down | Verify URL is https://api.shasta.trongrid.io |
Invalid private key | Hex with 0x prefix or wrong length | Use 64-char hex (no 0x prefix) |
Related resources
- Smart contracts overview — chapter map
- TronBox documentation — full TronBox reference
- TronWeb SDK — JavaScript SDK for in-app contract interaction
Updated 7 days ago