TronWeb/TronNetwork
TronWeb is a library that allows you to interact with TronNetwork
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. At the same time, TronWeb can service for Tron Network and Sun Network. Developers can use methods in tronWeb.sidechain to contact between the main chain and the side chain.
Installation
Node.js
npm install tronweb
or
yarn add tronweb
Browser
First, don't use the release section of this repo, it has not updated in a long time.
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>
Create TronWeb Instance
In order to use tronWeb in your application, you need to create a tronWeb instance like the following.
Create a tronWeb instance without sidechain options
const TronWeb = require('tronweb')
const HttpProvider = TronWeb.providers.HttpProvider;
let fullNode = '';
let solidityNode = '';
let eventServer = '';
const privateKey = '';
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
Create a tronWeb instance with sidechain options
const TronWeb = require('tronweb');
let fullNode = '';
let solidityNode = '';
let eventServer = '';
let sideOptions = {
fullNode: '',
solidityNode: '',
eventServer: '',
mainGatewayAddress: '',
sideGatewayAddress: '',
sideChainId: ''
}
const privateKey = '';
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,sideOptions,privateKey);
If you want to use shasta testnet, you can create an TronWeb instance as follows:
const TronWeb = require('tronweb');
const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = 'xxx';
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
And if you prefer to use our tronex testnet with a sidechain, you can create an TronWeb instance as follows:
const fullNode = 'https://testhttpapi.tronex.io';
const solidityNode = 'https://testhttpapi.tronex.io';
const eventServer = 'https://testhttpapi.tronex.io';
const sideOptions = {
fullNode: 'https://suntest.tronex.io',
solidityNode: 'https://suntest.tronex.io',
eventServer: 'https://suntest.tronex.io',
mainGatewayAddress: 'TFLtPoEtVJBMcj6kZPrQrwEdM3W3shxsBU',
sideGatewayAddress: 'TRDepx5KoQ8oNbFVZ5sogwUxtdYmATDRgX',
sideChainId: '413AF23F37DA0D48234FDD43D89931E98E1144481B'
}
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
{
fullNode: sideOptions.fullNode,
solidityNode: sideOptions.solidityNode,
eventServer: sideOptions.eventServer,
mainGatewayAddress: sideOptions.mainGatewayAddress,
sideGatewayAddress: sideOptions.sideGatewayAddress,
sideChainId: sideOptions.sideChainId
}
);
APIs
TronWeb API please refer to: API
Updated over 2 years ago