DEV Community

Cover image for Deploying a Smart Contract on the TRON Blockchain
Hannu-Daniel Goiss
Hannu-Daniel Goiss

Posted on

Deploying a Smart Contract on the TRON Blockchain

What is a Smart Contract?
A smart contract is a program that is stored and executed on blockchain nodes. It allows turning a blockchain into a “server” running “apps” instead of just using it to store data.

What is TRON?
Tron is a decentralized blockchain network. Check out https://tron.network for more information

First Step: get the IDE
go to https://developers.tron.network/docs/setup-dapp-environment-1 and follow the link for Tron-IDE to verify the pre-requisites
Pre-requisites:
1) Google Chrome
2) TronLink wallet (get the extension from the Google Chrome app store) – This will need to be configured for the correct network (Shasta Testnet for testing purposes) and it will require some $TRX, which are available for free in the Testnet. More about that later.

Once the pre-requisites are met, open http://www.tronide.io/ in the Google Chrome browser!
Voila, we have the IDE!
Tron IDE

Second Step: create the Solidity Script
First, create a new sample file. Let's call it Poem.sol

pragma solidity >=0.7.0 <0.9.0;

// this is to write a poem. whenever someone wants to add a line, he can call addLine.
// added text can never be removed
contract Poem {
    string public text;

    // retrieve the current status of the poem
    function get() public view returns (string) {
        return text;
    }

    // add text to the poem
    function addLine(added_text) public {
        text = text + added_text;
    }
}
Enter fullscreen mode Exit fullscreen mode

THIRD STEP: COMPILE
Navigate to the "Plugin-Manager" and activate the “Solidity Compiler”.
Plugin-Manager with deactivated modules

The "Solidity Compiler" will be added to the list of active modules and as a new menu option:
Plugin-Manager with activated Solidity Compiler

FOURTH STEP: RESOLVE ISSUES
Navigate to the "Solidity Compiler" module and click on "Compile".
I am now realizing a lot of issues in my code! Omg! Panic!
Solidity Compiler with warning and error messages

There is a warning about a license identifier and an error about a missing identifier in line 14.

DeclarationError: Identifier not found or not unique.
--> browser/Poem.sol:14:22:
|
14 | function addLine(added_text) public {
| ^^^^^^^^^^
Enter fullscreen mode Exit fullscreen mode

There is also an additional fix required in line 9, where I have defined String as the return parameter.
I realize that Solidity does not offer the ability to concatenate two strings. A workaround would be to use a function called encodePacked. (There is a reason why Solidity doesn't offer a concatenate function. Concatenating strings is an expensive function and should not be done on the Blockchain, but for this sample I will not care.)

To resolve all of these issues, let's change Poem.sol to:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

// this is to write a poem. whenever someone wants to add a line, he can call addLine.
// added text can never be removed
contract Poem {
    string public text;

    // retrieve the current status of the poem
    function get() public view returns (string memory) {
        return text;
    }

    // add text to the poem
    function addLine(string memory added_text) public {
        text = string(abi.encodePacked(text,added_text));
    }
}
Enter fullscreen mode Exit fullscreen mode

All issues are resolved and re-compilation is successful.
Successful Compiler Message

FIFTH STEP: DEPLOY
Go back to the Plugin Manager and activate the DEPLOYMENT Plugin.
Plugin-Manager to activate the DEPLOYMENT Plugin

The deployment plugin is now active. I had to re-compile Poem.sol after I activated the Deployment plugin for the Deployment plugin to work...

Deployment Plugin

Now login the the "Tronlink wallet Google Chrome app extension" and select the "TRON Shasta Testnet" in the dropdown on top.
TronLink wallet connected to Shasta TESTNET

Next, click on DEPLOY in the Deployment Plugin of the IDE. (Hint: this will not be successful unless you have sufficient funds.)

Request Test TRX tokens through: https://www.trongrid.io/shasta/ (This is also mentioned through https://developers.tron.network/docs/tron-grid-intro . I just added my Shasta wallet address to a Twitter post and got the TRX tokens after a few minutes.)
I received 10000 TRX in my Testnet wallet. Take care to use a different wallet address than in your TronGrid Mainnet wallet.

Once you made sure that you have sufficient funds, click on DEPLOY.

WALLET #1

WALLET #2

I have successfully deployed a Smart Contract on TRON!
TRON Smart Contract successfully deployed!

Discussion (0)