Start with TronWeb
TronWeb is a JavaScript SDK for TRON. It is designed for web browsers, Node.js, and IoT devices. If you are familiar with web3, TronWeb will bring you the same brilliant experience.
Installation
Either npm
or yarn
is available for installation.
Initialization
Create a TronWeb instance before other actions:
Interacting with Contracts
You are able to load a smart contract in a JavaScript variable. Take Comptroller
as an example:
All set. Now you can call contract methods with comptroller
.
Calling Contract Methods
Constant Calls
You can call pure
and view
methods with methodname.call()
. Take getAccountLiquidity
as an example:
When calling other methods, simply change getAccountLiquidity
to the corresponding method name and input the correct parameters within the brackets.
If a contract's ABI is not stored on the blockchain, ABI should be manually loaded and _isConstant: true
is required, like below.
Trigger Calls
Calls that modify on-chain data are called trigger calls. Take castVote()
as an example:
There are several available parameters in a trigger call:
Parameter | Description |
---|---|
feeLimit | The maximum energy can be used during a trigger call(in 10^-6 TRX, or sun) Please refer to TRON Energy Explanation |
callValue | The number of TRX to be sent in the transaction(in 10^-6 TRX, or sun) |
shouldPollResponse | Returns after confirmation if set as |
Please refer to TronWeb Documentation for details.
Last updated