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>
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 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 asTronWeb.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 as01
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 extension and develop a dapp on tron, you could run the demo in the path demo/tron-dapp-react-demo.
If you'd like to develop only with tronweb dependency, you could run the demo in the path demo/tronweb-demo.
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.