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:
Please refer to TronWeb Documentation for details.
Last updated