How to make Solidity based smart contracts async & DApps less complex within the TRON network

CaptainJS
2 min readMay 21, 2019

--

First things first: Why?

A smart contract can only be as smart as the programming language allows it to be smart. And Ethereum’s programming language Solidity is very, very basic. Tron uses Solidity, too, and thus has the same limits.

At the moment Solidity reduces a smart contract to only store values and to do some basic mathematical operations. It is completely synchronous and most of the smart logic is written outside of the smart contract: in a DApp or in a server.

What are the 2 scenarios for async calls in #TRON?

  • External calls… to databases, web services, (distributed) file systems, mail services, to a NodeJS oracle to overcome Solidity's limits, etc.
  • Automatic callbacks… to the contract itself to invoke code later (such as dividend payouts)

In order to implement these two scenarios, I needed to extend TRON. And here’s how to do it:

Step #1: Download the client library

Step #2: Create your smart contract

You may reuse the HelloSeaman_v1.sol example which is located in the client library. Just extend your contract from usingCaptainJSAtTron_v2 and the whole magic will start to happen:

To implement async calls in TRON just use either the Run-method for executing NodeJS-code, or invoke the Callback-method for simple callbacks.

Step #3: Invoke your contract with Tronweb

After you deployed your contract to SHASTA edit the Test-Shasta-public.js file from the GitHub repository and

  • add your private key (line 6)
  • change the contract’s address (line 11) — otherwise you’ll call my demo contract :-)
  • invoke SetCaptainsAddress() in the first run

That’s it. Have fun testing it on SHASTA!

All use cases documented for Ethereum are working with TRON, too. I will be happy if TRON Foundation and others help me hardening the service.

--

--