Getting Started with Java-tron: A Beginner's Guide

·

This guide provides a comprehensive overview of how to start a Java-tron node and interact with it using the command-line tool wallet-cli. It is assumed that Java-tron and its associated development tools are already installed on your system.

Introduction to Java-tron

Java-tron is the official Java implementation of the TRON network client. When you run Java-tron, your computer becomes a node within the decentralized TRON network. Unlike centralized systems, the TRON network operates on a peer-to-peer basis where information is shared directly between nodes. Super Representative nodes produce new blocks and broadcast them to other nodes. Each node validates incoming blocks before adding them to its local database. Java-tron updates its internal state—tracking every account's balance—using the information from these blocks.

The TRON network supports two primary account types:

This tutorial will walk you through creating an EOA, acquiring TRX tokens, and performing a TRX transfer.

Generating a New Account

The first step to using the TRON network is generating an account. While there are several methods to create an account, this guide demonstrates the process using the wallet-cli tool.

  1. Start the wallet-cli by running the following command in your terminal:

    java -jar wallet-cli.jar
  2. You will be greeted with a welcome message and a prompt. Type the command registerwallet.
  3. You will be prompted to input and confirm a password. This command generates a new TRON account and registers it within wallet-cli, which stores the private key for future transaction signing.
  4. Upon success, the CLI will confirm the registration and display the name of the generated keystore file.

Logging Into wallet-cli

After registering, you need to log in to manage your account.

  1. At the wallet prompt, enter the command login.
  2. You will be presented with a list of stored accounts. Select the number corresponding to your desired account.
  3. Enter your password. A "Login successful !!!" message confirms you are now logged in.
  4. Once logged in, you can view your account address using the getaddress command.
  5. It is highly recommended to back up your private key. Use the backupwallet command, enter your password when prompted, and securely store the displayed private key.

Starting a Java-tron Node

A Java-tron node is required to connect to and interact with the TRON network. This guide uses the Nile testnet.

  1. Ensure you have the Java-tron executable JAR file.
  2. Start the node with a command similar to the following (adjust memory parameters based on your system resources):

    java -Xmx24g -XX:+UseConcMarkSweepGC -jar FullNode.jar -c nile_net_config.conf
  3. Review the startup logs. Initial logs will display network configuration details (e.g., P2P version, IP addresses, listen port). Subsequently, logs will show the node discovering and syncing blocks from peer nodes.
  4. To verify the node is running correctly, you can send an HTTP request to it:

    curl http://127.0.0.1:16887/wallet/getnodeinfo
  5. To check sync status, compare the block height returned by your local node's /wallet/getnowblock endpoint with the current block height shown on a block explorer like Tronscan for the Nile testnet. If they match, your node is fully synchronized.
  6. To gracefully shut down the node, use the command kill -15 [process_id].

Acquiring TRX Test Tokens

To perform transactions like transfers, your account needs TRX. On the mainnet, TRX is obtained through block rewards, voting rewards, transfers from other accounts, or exchanges. On the Nile testnet, TRX holds no real value and can be acquired for free from a Faucet.

Interacting with Java-tron Using wallet-cli

Java-tron provides gRPC and HTTP interfaces. Wallet-cli is a command-line tool that uses the gRPC interface to offer a user-friendly way to interact with a node.

Checking Account Information

Use the getaccount command followed by an address to retrieve detailed information about an account, including its balance and creation time.

wallet> getaccount [address]

Checking Account Balance

The getbalance command quickly displays the TRX balance (in Sun) of the currently logged-in account.

wallet> getbalance

Transferring TRX

The sendcoin command allows you to send TRX to another address.

  1. Use the command: sendcoin [to_address] [amount]
  2. The CLI will display the unsigned transaction details. Confirm the transaction by typing y.
  3. Select the keystore file of the account you wish to sign with.
  4. Enter your password to sign the transaction.
  5. Wallet-cli will then broadcast the signed transaction. A success message and the transaction ID (txid) will be displayed upon success.

Querying Transactions by ID

After broadcasting a transaction, you can query its details and receipt using its txid.

👉 Explore more strategies for on-chain analysis

Interacting with Java-tron Using Curl

You can interact directly with the node's HTTP API (port 16887 by default) using tools like curl.

Checking an Account Balance

Use the wallet/getaccount endpoint to query balance information. The balance field in the response is the TRX balance in Sun.

curl -X POST http://127.0.0.1:16887/wallet/getaccount -d '{"address": "TUoHaVjx7n5xz8LwPRDckgFrDWhMhuSuJM", "visible": true}'

Sending a Transaction

Sending a transaction via HTTP is a three-step process: create, sign, and broadcast.

  1. Create an Unsigned Transaction: Use the wallet/createtransaction endpoint to generate a transaction object.

    curl -X POST http://127.0.0.1:16887/wallet/createtransaction -d '{"to_address": "TUznHJfHe6gdYY7gvWmf6bNZHuPHDZtowf", "owner_address": "TUoHaVjx7n5xz8LwPRDckgFrDWhMhuSuJM", "amount": 10000000, "visible":true}'
  2. Sign the Transaction: You must use a TRON SDK (e.g., TronWeb, java-tron SDK) or another secure method to sign the raw transaction hex (raw_data_hex) from the previous step with the private key of the owner_address. This cannot be done with curl alone.
  3. Broadcast the Signed Transaction: Submit the signed transaction object (including the signature and raw_data) to the wallet/broadcasttransaction endpoint.

    curl -X POST http://127.0.0.1:16887/wallet/broadcasttransaction -H "Content-Type: application/json" -d '{"visible": true, "signature": ["SIGNATURE_HERE"], "txID": "TXID_HERE", "raw_data": { ... }, "raw_data_hex": "RAW_HEX_HERE"}'

    A response with "result": true indicates successful broadcast.

Querying Transactions by ID

You can also query transactions using their ID via HTTP.

Frequently Asked Questions

What is the difference between an Externally Owned Account and a Contract Account?
An Externally Owned Account (EOA) is controlled by a private key and is used to send transactions and sign messages. A Contract Account is controlled by its internal code and only activates when it receives a transaction from an EOA, executing the logic defined in its smart contract.

Why is my Java-tron node not syncing blocks?
Ensure your node has an active internet connection and the correct configuration file for the network you want to join (e.g., Nile testnet). Check the logs for connection errors. Firewall settings or network configuration might be blocking peer-to-peer communication on port 18888.

What is SUN, and how does it relate to TRX?
SUN is the smallest unit of TRX, similar to how Satoshi is to Bitcoin. 1 TRX = 1,000,000 SUN. The network often uses SUN for internal calculations and API calls to avoid decimals.

I lost my private key. Can I recover my account?
No. The private key is the ultimate proof of ownership for an account. If you lose it and haven't backed it up, there is no way to recover the assets in that account. Always store your private key and keystore file securely.

Can I use the same steps for the TRON Mainnet?
Yes, the core technical steps for running a node and interacting with it are identical. However, you must use the mainnet configuration file and acquire real TRX from an exchange to perform transactions. 👉 Get advanced methods for mainnet deployment

What does the 'net_usage' in a transaction receipt mean?
Net_usage represents the Bandwidth Points consumed by the transaction. Every transaction on the TRON network consumes bandwidth, which is calculated based on the size of the transaction data. Users have a free bandwidth allowance that resets every 24 hours.