Skip to content

Getting Started

This guide is your launchpad into the TRON ecosystem. By the end of it, you will have a deployed smart contract and a solid understanding of the underlying tooling, resource management, and secure network bridging. We assume basic knowledge of JavaScript and Solidity — let’s get building.

Before writing any code, ensure your local environment has the essentials:

  • Node.js v18 or later (node --version)
  • npm or yarn
  • TronLink browser extension (your bridge to the network)

Step 1 — Create Your Developer Sandbox (Wallet)

Section titled “Step 1 — Create Your Developer Sandbox (Wallet)”

You should never mix your personal funds with development. Development tools require access to private keys to sign deployments, and by creating a dedicated, isolated “sandbox” wallet, you completely eliminate the risk of accidentally burning real TRX on a botched test script.

  1. Open TronLink and click the account icon → Add AccountCreate Account.
  2. Name it clearly, like “Dev - Testnet”.
  3. Back up the seed phrase. Yes, it’s a dev wallet, but losing access means losing your testnet history and having to configure everything again.
  4. Copy the wallet address (T-prefix, 34 characters). This is your identity on the network.

Every operation that modifies the blockchain (like deploying a contract) consumes network resources (Energy and Bandwidth). On the Mainnet, this costs real TRX. On a testnet, you use free, valueless “Testnet TRX” to simulate these costs without financial risk.

TRON maintains two primary public testnets:

  • Nile: The cutting-edge testnet. It usually contains the latest protocol upgrades, making it the best place to test new features.
  • Shasta: The stable testnet. It mirrors the mainnet environment perfectly, which is great for final staging.

For general development and following this guide, we’ll use Nile since it’s the standard sandbox for new developers. Let’s fund your wallet:

  1. Head over to the Nile Faucet.
  2. Paste your new dev wallet address, complete the reCAPTCHA, and click Obtain.
  3. Verify the deposit: Check your balance on the Nile Explorer (TRONSCAN).

Step 3 — Install TronBox (Your Command Center)

Section titled “Step 3 — Install TronBox (Your Command Center)”

Compiling Solidity down to bytecode and manually pushing it to the blockchain via raw HTTP requests is tedious and error-prone. TronBox is the standard framework that automates the compilation, deployment, and testing pipeline, keeping your project organized.

Terminal
# Task: Install the TronBox framework globally so you can use it from any directory.
npm install -g tronbox
tronbox --version

Let’s scaffold a clean working directory:

Terminal
# Task: Initialize a new TronBox project to generate the required directory structure.
mkdir my-tron-project
cd my-tron-project
tronbox init

TronBox creates a standard structure for you:

  • /contracts/: Where your raw Solidity files live.
  • /migrations/: Scripts that dictate exactly how your contracts should be deployed.
  • /test/: Where you’ll write tests to ensure your logic is bulletproof.
  • tronbox.js: The master configuration file.

Step 4 — Wire Up the Network (tronbox.js)

Section titled “Step 4 — Wire Up the Network (tronbox.js)”

TronBox needs to know where to deploy your contracts (the network endpoints) and who is paying for the deployment (your dev wallet’s private key). We use environment variables (.env) to inject the private key dynamically so it never gets hardcoded into your source files.

Replace the contents of tronbox.js with this configuration:

tronbox.js
// Task: Tell TronBox how to connect to the Nile testnet securely.
module.exports = {
networks: {
nile: {
privateKey: process.env.PRIVATE_KEY_NILE,
userFeePercentage: 100,
feeLimit: 1000000000,
fullHost: 'https://nile.trongrid.io',
network_id: '3',
},
mainnet: {
privateKey: process.env.PRIVATE_KEY_MAINNET,
userFeePercentage: 100,
feeLimit: 1000000000,
fullHost: 'https://api.trongrid.io',
network_id: '1',
},
},
compilers: {
solc: {
version: '0.8.18',
},
},
};

Create a .env file in the root of your project (and immediately add it to your .gitignore!):

.env
# Task: Securely store your testnet private key away from source control.
PRIVATE_KEY_NILE=your_nile_dev_wallet_private_key_here

(To get your private key: Open TronLink → select your dev account → click the three-dot menu → Export Account).


Step 5 — Write & Compile Your First Contract

Section titled “Step 5 — Write & Compile Your First Contract”

TRON’s Virtual Machine (TVM) is highly compatible with the Ethereum Virtual Machine (EVM). This means we write our contracts in Solidity. When we compile, TronBox translates this human-readable Solidity into machine-readable bytecode and generates an ABI (Application Binary Interface), which serves as a “manual” for how frontends can interact with the contract.

Create a new file at contracts/SimpleStorage.sol:

SimpleStorage.sol
// Task: Define a minimal contract that stores and retrieves a single number.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract SimpleStorage {
uint256 private value;
// Events let frontends listen for changes on the blockchain
event ValueSet(uint256 indexed newValue, address indexed setter);
// 'external' functions can be called by users or other contracts
function set(uint256 _value) external {
value = _value;
emit ValueSet(_value, msg.sender);
}
// 'view' means this function reads data but doesn't modify the blockchain
function get() external view returns (uint256) {
return value;
}
}

Now, command TronBox to compile it:

Terminal
# Task: Translate the Solidity code into TVM-ready bytecode and ABI.
tronbox compile

Look inside the build/contracts/ folder. TronBox just generated the artifacts needed for deployment.


Step 6 — Map Out the Deployment (Migration)

Section titled “Step 6 — Map Out the Deployment (Migration)”

A blockchain is a state machine. “Migrating” simply means moving the blockchain from its current state to a new state that includes your contract. The migration script tells TronBox exactly which contracts to deploy and in what order.

Create migrations/2_deploy_simple_storage.js:

2_deploy_simple_storage.js
// Task: Instruct TronBox to deploy the SimpleStorage contract artifact.
const SimpleStorage = artifacts.require('SimpleStorage');
module.exports = function (deployer) {
deployer.deploy(SimpleStorage);
};

It’s time to make it real. By running the migrate command, TronBox will construct a deployment transaction, sign it with your .env private key, and broadcast it to the Nile network. The network will deduct Testnet TRX (Energy/Bandwidth) to permanently store your contract’s bytecode.

Terminal
# Task: Broadcast your contract to the network to make it live.
source .env # Load your private key into the terminal session
tronbox migrate --network nile

Watch the terminal. TronBox will output a deployed contract address (starting with T...). Copy this address.

Victory Check: Go to nile.tronscan.org and search for your new contract address. You’ll see the exact Energy consumed and the verified deployment transaction. You are officially live on TRON.


A smart contract isn’t very useful if nobody can talk to it. tronweb is the official JavaScript SDK. We use it to bridge a Node.js script (or a React frontend) directly to the blockchain to execute our set() and get() functions.

First, install the SDK:

Terminal
# Task: Add the TronWeb SDK to your project to enable blockchain communication.
npm install tronweb

Create scripts/interact.js:

interact.js
// Task: Use TronWeb to read from and write to your live contract.
import TronWeb from "tronweb"
// Initialize TronWeb with the Nile endpoint and your dev key
const tronWeb = new TronWeb({
fullHost: 'https://nile.trongrid.io',
privateKey: process.env.PRIVATE_KEY_NILE,
});
const CONTRACT_ADDRESS = 'T...'; // Paste your deployed address here!
async function main() {
// Load the ABI so TronWeb knows what functions exist
const contract = await tronWeb.contract().at(CONTRACT_ADDRESS);
console.log('Executing write operation...');
// .send() creates a transaction, burns Energy, and alters the blockchain state
const tx = await contract.set(42).send();
console.log('Transaction hash:', tx);
console.log('Executing read operation...');
// .call() is a free, local query to a node. It doesn't alter state.
const result = await contract.get().call();
console.log('Value currently stored on-chain:', result.toString());
}
main().catch(console.error);

Run your interaction script:

Terminal
# Task: Execute the script to talk to the Nile testnet.
node scripts/interact.js

Congratulations! You’ve successfully completed the full lifecycle of DApp development on TRON. You now have:

  • A secure developer wallet funded with Testnet TRX.
  • TronBox configured to manage your compilations and deployments.
  • A live smart contract running on the Nile testnet.
  • A Node.js script using tronweb to read from and write to the blockchain.

You have the foundation. Now it’s time to build something complex.


Solidity Basics

Need a refresher on the language? Review Solidity syntax, EVM compatibility, and TRON-specific patterns.

Read the Primer →

tronweb SDK

Want to build a frontend? Get the full reference for account management, transaction signing, and event listening.

Master the SDK →

Fee Model & Resources

Wondering why deployments cost Energy? Learn how TRON’s resource model differs from traditional gas.

Understand TRON Fees →