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 version

Expected 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 init

This 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 naming

TronBox accepts both tronbox.js and tronbox-config.js. This guide uses tronbox-config.js because the tronbox.js filename can collide with the tronbox executable 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 key

Use the process.env.PRIVATE_KEY pattern shown above and set the value in your shell session, or use a .env file plus dotenv. Hard-coding a key in source has caused many compromised mainnet accounts.

Step 5 — Compile

tronbox compile

Expected 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 shasta

Expected 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 shasta

The 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


Common errors

ErrorCauseFix
command not found: tronboxTronBox not in PATHRun npm install -g tronbox; add npm global bin to PATH
Compiler version mismatchpragma and tronbox-config.js differSet both to the same version
Insufficient balanceDeployer has no TRXVisit the Shasta faucet
Network connection errorfullHost wrong / network downVerify URL is https://api.shasta.trongrid.io
Invalid private keyHex with 0x prefix or wrong lengthUse 64-char hex (no 0x prefix)

Related resources