Skip to main content
Version: 5.0.0

Introduction

TronWeb aims to deliver a unified, seamless development experience influenced by Ethereum's Web3 implementation. We have taken the core ideas and expanded upon it to unlock the functionality of TRON's unique feature set along with offering new tools for integrating DApps in the browser, Node.js and IoT devices.

Getting Started

Installation

Node.js

npm install tronweb

or

yarn add tronweb

Browser

Then easiest way to use TronWeb in a browser is to install it as above and copy the dist file to your working folder. For example:

cp node_modules/tronweb/dist/TronWeb.js ./js/tronweb.js

so that you can call it in your HTML page as

<script src="./js/tronweb.js"><script>

Instantiation

Then your javascript file, define TronWeb:

const TronWeb = require('tronweb');

When you instantiate TronWeb you can set

  • fullHost

Supposing you are using a server which provides everything, like TronGrid, you can instantiate TronWeb as:

const tronWeb = new TronWeb({
  fullHost: 'https://api.trongrid.io',
  headers: { 'TRON-PRO-API-KEY': 'your api key' },
  privateKey: 'your private key'
});

Like infura API Key, you can sign up for TronGrid and create your API key on the dashboard to access TRON Network data.

Note:

  • Do not expose your private key in any web browser environment.
  • You can instantiate TronWeb without privateKey, if you only need to use some utils functions such as TronWeb.utils
  • If you only want to query information from TRON Network blockchain without signing a transaction with instantiated tronweb, such as getTransactionInfo, triggerconstantcontract, you can pass a public private key such as 01 to instantiate TronWeb.

Compatibility

  • Version built for Node.js v6 and above
  • Version built for browsers with more than 0.25% market share

TronWeb is also compatible with frontend frameworks such as:

  • Angular
  • React
  • Vue.

You can also ship TronWeb in a Chrome extension such as TronLink extension

A full DApp example

The better way to understand how to work with TronWeb is going to the demo directory in TronWeb repository.

If you'd like to connect with tronlink app and chrome extention and develop a dapp on tron, you could run the demo in path demo/tron-dapp-react-demo.

If you'd like to develop only with tronweb dependency, you could run the demo in path demo/tronweb-demo.

Intaract with TRON wallets

TronProtocol organization supports wallet adapters for DApp developers, which suports TronLink Extension (Chrome and Firefox), TronLink APP (Android/iOS), Ledger, Walletconnnect at present.