TronWeb

TronWeb is the JavaScript SDK maintained by the TRON developer community for interacting with the TRON blockchain.

📘

Prerequisites

TronWeb is the JavaScript SDK maintained by the TRON developer community for interacting with the TRON blockchain. It exposes a complete interface set — account management, transaction construction, smart contract interaction, and node communication — for building and integrating DApps across browsers, Node.js, and IoT environments.

TronWeb borrows its API shape from Ethereum’s Web3.js, so developers migrating from Ethereum feel at home; on top of that, it adds a dedicated set of interfaces for TRON-specific features such as the resource model, TRC-10, and Stake 2.0.

Quick start

npm install tronweb
import { TronWeb } from 'tronweb';

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

const address = tronWeb.defaultAddress.base58;
const balance = await tronWeb.trx.getBalance(address);

console.log('Address:', address);
console.log('TRX:', tronWeb.fromSun(balance));

Do not put private keys in frontend DApp code. Browser apps should request user signatures through TronLink or a wallet adapter. Backend scripts, batch jobs, and controlled test scripts can load private keys from environment variables.

Common pitfalls

  • Amounts are usually denominated in sun; 1 TRX = 1,000,000 sun.
  • When node HTTP APIs use Base58Check addresses, set visible: true.
  • State-changing contract transactions need a reasonable fee_limit; it caps available Energy, not just "the maximum TRX to burn."
  • Mainnet TronGrid requests usually need a TRON-PRO-API-KEY; Shasta and Nile examples can start without one.

For more information, refer to the TronWeb project resources: