Send your first transaction

End-to-end tutorial: install TronWeb, generate keys, fund a Shasta testnet account, and broadcast your first TRX transfer in 15 minutes.

📘

Prerequisites

This tutorial walks through your first TRX transaction on the TRON Shasta testnet. You will install TronWeb, generate a key pair, obtain test tokens, build and sign a transaction, broadcast it, and verify the result on TronScan. The full flow takes about 15 minutes.

💡

Just want the code?

See the Send your first transaction recipe — same flow, condensed to a copy-paste snippet with a cost summary and error table.


Step 1 — Install TronWeb

Create a new project and install TronWeb, the JavaScript SDK for TRON (analogous to Ethereum's web3.js):

mkdir tron-hello && cd tron-hello
npm init -y
npm install tronweb

Step 2 — Generate a key pair

Every TRON account is controlled by a private key. Generate a new key pair:

const { TronWeb } = require('tronweb');

// Generate a random account
const account = TronWeb.createRandom();
console.log('Address (Base58):', account.address);
console.log('Private Key:', account.privateKey);
// Save these — you will need them in the next steps
🚧

Never share your private key

Anyone with the private key controls the account. This tutorial uses the testnet, where tokens have no real value, but treat the key the same way you would on Mainnet.


Step 3 — Get testnet TRX

Visit the Faucet and paste your Base58 address to receive test TRX. Keep test TRX in addition to the 10 TRX transfer amount to cover possible Bandwidth and account-activation costs. If the recipient is not activated, this transfer creates its onchain account state. These costs are controlled by the current chain parameters; query wallet/getchainparameters before sending. See Account activation.


Step 4 — Send 10 TRX

Create a file called send.js:

const { TronWeb } = require('tronweb');

const privateKey = process.env.TRON_PRIVATE_KEY;
if (!/^[0-9a-fA-F]{64}$/.test(privateKey || '')) {
  throw new Error('Set TRON_PRIVATE_KEY to a 64-character hexadecimal Shasta test private key');
}

const tronWeb = new TronWeb({
  fullHost: 'https://api.shasta.trongrid.io',
  privateKey
});

async function sendTrx() {
  const to = 'TJRabPrwbZy45sbavfcjinPJC18kjpRTv8'; // any valid address
  const amount = 10 * 1_000_000; // 10 TRX in sun (1 TRX = 1,000,000 sun)

  // Build → Sign → Broadcast
  const tx = await tronWeb.transactionBuilder.sendTrx(to, amount);
  const signed = await tronWeb.trx.sign(tx);
  const result = await tronWeb.trx.sendRawTransaction(signed);

  console.log('Transaction ID:', result.txid);
  console.log('Success:', result.result);
}

sendTrx();

Run it:

read -s TRON_PRIVATE_KEY
export TRON_PRIVATE_KEY
node send.js
# Output: Transaction ID: 5f3e4e0a... Success: true
unset TRON_PRIVATE_KEY

Step 5 — Verify on TronScan

Open https://shasta.tronscan.org/#/transaction/<YOUR_TX_ID> in your browser. You will see the sender, recipient, amount (10 TRX), and confirmation status. TRON normally produces a block every three seconds, so the transaction will usually appear in a block quickly; solidification requires additional blocks.


Java alternative (Trident SDK)

This example uses JDK 8 or 17, Maven 3.8+, and Trident 1.0.0. In an empty directory, create pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example</groupId>
  <artifactId>send-trx</artifactId>
  <version>1.0.0</version>
  <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
      <groupId>io.github.tronprotocol</groupId>
      <artifactId>trident</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.5.1</version>
      </plugin>
    </plugins>
  </build>
</project>

Create the source directory:

mkdir -p src/main/java

Save the following class as src/main/java/SendTrx.java:

import org.tron.trident.core.ApiWrapper;
import org.tron.trident.proto.Chain.Transaction;
import org.tron.trident.proto.Response.TransactionExtention;

public class SendTrx {
    public static void main(String[] args) throws Exception {
        String privateKey = System.getenv("TRON_PRIVATE_KEY");
        if (privateKey == null || !privateKey.matches("[0-9a-fA-F]{64}")) {
            throw new IllegalArgumentException("TRON_PRIVATE_KEY must contain 64 hexadecimal characters");
        }
        ApiWrapper client = ApiWrapper.ofShasta(privateKey);
        try {
            String senderAddress = client.keyPair.toBase58CheckAddress();
            TransactionExtention tx = client.transfer(
                senderAddress, "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8", 10_000_000L);
            Transaction signed = client.signTransaction(tx);
            String txid = client.broadcastTransaction(signed);
            System.out.println("Transaction ID: " + txid);
        } finally {
            client.close();
        }
    }
}

Set the private key of a funded Shasta test account and run the class:

read -s TRON_PRIVATE_KEY
export TRON_PRIVATE_KEY
mvn -q compile exec:java -Dexec.mainClass=SendTrx
unset TRON_PRIVATE_KEY

What happened under the hood

  1. Transaction construction. TronWeb created a TransferContract transaction — one of TRON's system contract types.
  2. Signing. Your private key produced an ECDSA (secp256k1) digital signature.
  3. Broadcasting. The signed transaction was sent to a full node via HTTP API.
  4. Block inclusion. A Super Representative can include it in a subsequent block; TRON normally produces a block every three seconds.
  5. Resource cost. This simple transfer consumed Bandwidth but no Energy. The current getFreeNetLimit parameter gives each account 600 Bandwidth, with usage recovering over a rolling 24-hour window. A typical TRX transfer consumes about 270 Bandwidth; whether TRX is burned depends on the transaction size and the account's available Bandwidth at that time.

Next steps


Related resources