Skip to main content
Version: v6.0.0

Introduction

release note

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 them 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

The 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>

❗️Note:

TronWeb dependents on Buffer and crypto. So please polyfill them manually.

Instantiation

Then your javascript file, define TronWeb:

const TronWeb = require('tronweb');

❗️Note:

As we all know there are two widely used ways of modules in the JS world, commonjs and esmodule. TronWeb supports these two ways of code importing starting from v6.0.0. So when you import using require, it will load the commonjs code. When you import using the import keyword, it will load the esmodule code.

When you instantiate TronWeb you can set

  • fullHost

Supposing you are using a server that 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 the 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 v14 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

Interact with TRON wallets

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