Getting Started with TRON’s Go SDK and CLI Tool

May 14, 2022 | Blockchain

Embarking on the journey to utilize TRON’s blockchain is exciting and rewarding. The Go SDK and TRON-CLI tool pave the way for powerful interactions with the blockchain through the GRPC interface. This guide will walk you through the setup, usage, and handling of common issues you may encounter.

Building the Tool

To get started, you will need to build the TRON Go SDK and CLI tool from the source.

  • First, pull the latest changes from the master branch:
  • git pull -r origin master
  • Next, run the following command to build the project:
  • make
  • If you need to cross-build for Windows, utilize:
  • make windows

Using the CLI Tool

Once you’ve built the tool, it’s time to add it to your system’s PATH and set up bash completions:

  • Add tronctl to your path and include it in your .bashrc:
  • tronctl completion

Transferring Assets Using JSON Format

Transferring assets via TRON blockchain is made simple with JSON format. Each transfer request is represented as a JSON object containing necessary fields.

The structure of the JSON file should include the following attributes:

  • from: string – Required; sender’s address, must exist in the keystore.
  • to: string – Required; receiver’s address.
  • amount: string – Required; the amount to send in $ONE.
  • passphrase-file: string – Optional; file path to passphrase in plain text.
  • passphrase-string: string – Optional; passphrase as plain text. Default is an empty string.
  • stop-on-error: boolean – Optional; if true, stop sending transactions upon encountering an error. Default is false.

Here is an example of a JSON file for asset transfer:

[
    {"from": "TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH", "to": "TKSXDA8HfE9E1y39RczVQ1ZascUEtaSToF", "amount": "1", "passphrase-string": "", "stop-on-error": true},
    {"from": "TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH", "to": "TEvHMZWyfjCAdDJEKYxYVL8rRpigddLC1R", "amount": "1", "passphrase-file": ".pw.txt"}
]

Understanding the Code: An Analogy

Consider setting up the Go SDK and CLI tool as preparing for a road trip. Pulling updates from the master branch is like checking your vehicle’s maintenance and ensuring it’s ready for the journey. The build process represents filling your gas tank – essential to keep you moving forward.

When you prepare your JSON for transferring assets, think of it as packing your bags with essentials: you must include who you’re sending things to, what you’re sending (the assets), and how much you’re sending (amount). Optional items, such as the passphrase, are like snacks for the journey—you don’t have to bring them, but they can make your trip smoother.

Troubleshooting Common Issues

While the setup should be straightforward, you may encounter some issues. Here are a few troubleshooting suggestions:

  • Debugging: If you face issues with the Go SDK, you can enable debugging by setting the environment variable:
  • export GOTRON_SDK_DEBUG=true
  • Make sure the paths to your keys and files are correct.
  • Check to ensure that your TRON node requires TLS if you’re using the --withTLS parameter.
  • For connecting to the Trongrid API, visit www.trongrid.io to create your API key. Ensure you replace the dummy key with your actual key in the configurations.
  • If you run into issues with API key settings, remember the environment variable TRONGRID_APIKEY will take precedence over any previous configurations.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox