How to Deploy a TRC-20 Token on TRON: A Developer Guide 

Deen Newman

Deen Newman

August 29, 2024

16 分鐘閱讀

article cover

The Tron blockchain has quickly become a top platform for users and developers, built to handle a large number of transactions per second, outperforming many other blockchains like Ethereum.

A major advantage of Tron is its very low transaction fees which makes Tron token development a popular choice for builders in Web 3 creating a new cryptocurrency, building a DeFi app, or adding tokens to their project.

This guide will take you step-by-step through the process of creating and deploying your token on Tron as a TRC-20 contract, from setting up your environment to launching it on the testnet or mainnet.

What is TRC-20?

TRC-20 is the blueprint for creating tokens on Tron, a technical standard used for smart contracts to issue tokens.

It is essentially a mirror of Ethereum's ERC-20 standard. This means that the functions and events defined in ERC-20 (like transfer, approve, transferFrom, totalSupply, etc.) are the same in TRC-20.

This compatibility allows developers to easily move Ethereum-based smart contracts written in Solidity to the TRON network with minimal or no changes — exactly what we’ll demonstrate in this guide.

How to Create a TRC-20 Token: Prerequisites

Before you can deploy a TRC-20 contract on the Tron network, ensure you have the necessary tools and environment set up.

Below is a list of the tools you’ll need:

  • TronBox: a framework similar to Truffle designed for TRON;
  • Tron Wallet: e.g. TronLink Wallet;
  • TRON REST API provided by GetBlock.

To start using TronBox, make sure NodeJS (version 8.10.0 or higher) is installed and properly configured on your machine.

Set Up the Tron Development Environment

To get started with TronBox, you need to install it on your system using a terminal:

npm install -g tronbox

If needed, refer to the official installation guide for troubleshooting tips.

Similar to Ethereum's Truffle, it helps compile, deploy, and manage smart contracts on TRON.

Deploy a Token on Tron: Step-by-Step Guide

In this guide, we’ll walk you through deploying a Solidity contract on TRON’s Nile test network using a free custom Tron node RPC by GetBlock.

You can follow the same steps to deploy a token on the TRON mainnet, while GetBlock provides developers with easy access to Tron blockchain through ready-to-use APIs.

You can follow the same steps to deploy a token on the TRON mainnet, while GetBlock provides developers with easy access to Tron blockchain through ready-to-use APIs.

Step 1: Obtain Your TRON API

The first step in deploying on TRON is to obtain an API that allows you to interact with the Tron blockchain. Here’s how you can get started:

  1. Sign up or log in to GetBlock: Head over to GetBlock and sign up using MetaMask or your email;
  2. Scroll down to "My Endpoints": Select TRON (Testnet) as your blockchain network and choose a Fullnode REST API;
  3. Generate your TRON API endpoint: Press “Get” and get a TRX RPC URL generated.
deploy_tron_token_with_custom_API

Source: GetBlock

This URL will be your access point for interacting with the Tron blockchain, handling everything from contract deployment to invoking functions.

Context Banner

Step 2: Create a New TronBox Project

Next, create a directory for your project and initialize a project inside it by running:

tronbox init
how_to_create_TRC-20_token

Once initialized, open the project in your preferred code editor.

Step 3: Write a Basic TRC-20 Smart Contract

Any ERC-20 contract code written in Solidity can generally be deployed on the TRON network as TRC-20 since the functions, interfaces, and storage mechanisms are all compatible.

To streamline the process, you can use the OpenZeppelin Wizard. It generates the contract code you can copy and reuse in TronBox.

how_to_deploy_TRC-20_contract

Source: OpenZeppelin

This contract, once deployed on the TRON network, will function as a TRC-20 token.

To work with OpenZeppelin libraries directly in TronBox, run the following command in your project directory to install the contracts library:

npm install @openzeppelin/contracts

Pro Tip: OpenZeppelin is an excellent resource, especially if you're new to smart contracts. For more details, refer to our guide on how to use OpenZeppelin.

Step 4: Create a TRC-20 Token Contract File

Inside the contracts folder, create a new file with a .sol extension. This is where you'll paste your Solidity code.

Tron_token_contract_code

Once ready, compile it:

tronbox compile

Step 5: Connect TronBox to GetBlock's TRON API

Let’s configure TronBox to use the GetBlock TRON Fullnode API.

In ‘**tronbox.js**’ file, set up the Nile testnet configuration to point to your GetBlock API endpoint. Here’s an example:

how_to_deploy_a_token_on_Tron_using_TronBox

Instead of directly inserting your private key into the config file, import it from a .env file – a more secure method of handling sensitive data.

This setup ensures that all your token deployments and interactions are routed through the secure and reliable GetBlock infrastructure.

Step 6: Define a Contract Deployment Script

Modify the deployment (migration) script that will handle the deployment of your TRC-20 token on the TRON network.

  1. Navigate to the migrations folder in your TronBox project, and open the ‘**2_deploy_contracts.js**’ file;
  2. Ensure the correct Solidity file is linked in the migration script (e.g. “TestToken.sol”).
how_to_deploy_a_TRC_20_token

If your contract doesn’t have any constructor parameters, you can simply deploy it as shown.

Step 7: Deploy to TRON

Before deploying, ensure your Tron wallet has testnet TRX to cover fees. One option is to request 2,000 test coins from the Nile Testnet Faucet to fund your wallet.

This command will deploy the contract to the Nile test network:

source .env && tronbox migrate --network nile
TRX_token_contract_deployment

Once this command completes, your Solidity contract will be successfully deployed on the TRON network’s Nile Testnet and provide your TRC-20 token address.

Step 9: Interact With the Tron Contract

After deploying your TRC-20 contract, you can interact with it directly in TronBox.

  1. Start by opening a console connected to the Nile Testnet:
tronbox console --network nile
  1. Once the console is open, you can call any available functions within your contract to interact with it.
deploying_Tron_token_with_TronBox

The TronWeb library used in the TronBox console provides similar functionality to web3.js in Ethereum: interacting with smart contracts deployed on the TRON blockchain.

Conclusion

You can deploy and interact with an ERC-20 token contract on Tron as a TRC-20 token because of the high degree of compatibility between the two standards. This design choice makes it easy for Ethereum developers to start building on Tron using similar tools.

Take the first step in launching your TRC-20 token with confidence with GetBlock. GetBlock offers the tools you need for seamless blockchain development. Sign up to access 50+ networks and RPC nodes, including TRON Mainnet and Testnet. Start free, scale when you're ready.

Deen Newman

Deen Newman

August 29, 2024

16 分鐘閱讀

twittertwittertelegramtelegramLinkedinLinkedin