How to deploy your first smart contracts on the TRON Nile testnet using GetBlock REST API

Hey, TRON Fam! Today I’d like to explore a great topic of TRON development - deploying smart contracts!
Let’s learn how to build on TRON! Shall we?! :rocket:

We are gonna learn how to deploy a Solidity contract on the TRON chain using GetBlock’s API. Here is our toolkit:

  • :point_right: NodeJS >=8.10.0
  • :point_right: TronBox
  • :point_right: Tron Wallet
  • :point_right: TRON NILE REST API by GetBlock

Before rolling out your dApps and smart contracts on Tron mainnet, it’s important to test their performance on the testnet! There are two main testnets for Tron - Nile and Shasta. We are gonna use Nile in this case as it’s a more flexible and highly used one.

Step 1: Set Up Your Environment

This step requires setting up a TronBox. Here are TronBox Environment Dependencies

  • NodeJS >=8
  • Windows, Linux or Mac OS X
  • Docker Engine >=v17

To get more insights on how to install the node.js and tronbox refer to the official TRON docs here: Install TronBox

Step 2: Grab your API from GetBlock

To interact with the TRON blockchain you need a robust API. You can grab such from GetBlock for free! Here’s how to do so:

:one: Sign up/in to https://getblock.io/ with MetaMask or email
:two: Navigate to ‘My Endpoints’. Select TRON (Testnet), generate a Fullnode REST API

We’ll use this RPC URL for deployment and further interactions with the contract

Step 3: Write a Solidity contract

Go to your IDE, we use Remix IDE in this example. Create a .sol file and write your code. We’ll use the very basic storage contract for this demo. You can also use your previous smart contracts and deploy them on TRON!
To compile the contract head to the direction where your project is located and past the following into a terminal: tronbox compile

Step 4: Configure Contract Deployment on Nile Testnet

Now we need to configure how and where our contract will be deployed.

  1. Open tronbox.js file in the root directory;
  2. Edit nile configuration:
  3. Insert the TRON wallet’s private key,
  4. adjust the fee limit,
  5. add the RPC URLs from GetBlock that you took on Step2

Step 5: Modify Migration (Deployment) Scripts

Go to the migrations folder and edit 2_deploy_contracts.js file:

  1. Add the path to your Solidity file: in this example, ./Storage.sol
  2. Define the deployment function
    If your contract has constructor parameters, you can pass them here.

Step 6: Deploy the Contract

Now we’re on the finish line! It’s time to finally Deploy your first TRON smart contract!
Make sure your TRON Wallet is pre-funded with testnet $TRX to cover deployment fees; you can request 2,000 test coins from the Nile Testnet Faucet
Once it’s done - run the Migration command in your terminal:
source .env && tronbox migrate --network nile

Congradulations! Your first Solidity contract is successfully deployed to TRON Nile Testnet!

Additionally, you can interact with your contract to check if everything is working correctly

  1. Request a TronBox console from the terminal: tronbox console --network nile
  2. Now you can interact with the contract calling available functions
    Well done! :tada:
    Now you’re one step closer to becoming a professional TRON builder! :sunglasses:
22 Likes

glad to see a member from GetBlock. thank you for this tutorial. do you provide also websocket api ? or only rest ?

1 Like

Appreciate the guide may consider using it in future. When will you be going mainnet?

3 Likes

i think they already have RPC for mainnet

4 Likes

yeah guys @Robert2 @modeling200
i just checked their website. both TRON chains are available - Mainnet and Testnet

3 Likes

Thanks for your feedback! Currently, the WebSocket API is supported only on dedicated node plans, but you can join our community on Discord and vote for it, so we might consider adding it in the future

2 Likes

Thanks for your kind words and sorry for the late response! As other guys just said, we support RPC for mainnet and testnet as well!

3 Likes

Thank You for this Tutorial :slight_smile:

1 Like

Do you support RPC for both mainnet and testnet?

2 Likes

Okay tried it already after that response. Thank you.

1 Like