What is Tron Station SDK?
Tron Station SDK - Developer Document
Tron Station SDK is a library for estimating Tron energy and bandwidth consumption based on Tron network. Developers can quickly review energy and bandwidth points information before deploying/triggering a smart contract or make a transaction.
Compatibility
- Version built for Node.js v6 and above
- Version built for browsers with more than 0.25% market share
Tron Station SDK is also compatible with frontend frameworks such as:
You can also ship Tron Station SDK in a Chrome extension.
Installation
Tron Station SDK - NPM Package
NPM
> npm install @tronscanteam/tronstation
Yarn
> yarn add @tronscanteam/tronstation
Build Steps
If you'd like to download and build locally, please follow the steps below.
> git clone https://github.com/TRON-US/tronstation-sdk
> cd tronstation-sdk
> yarn install
> yarn build
> yarn test
Usage
NPM
> npm install tronweb
Yarn
> yarn add tronweb
Initialize TronWeb and create Tron Station SDK instance
import TronStation from '@tronscanteam/tronstation';
import TronWeb from 'tronweb';
const fullNode = new HttpProvider('https://api.trongrid.io');
const solidityNode = new HttpProvider('https://api.trongrid.io');
const eventServer = new HttpProvider('https://api.trongrid.io');
const privateKey = 'your private key';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
const tronStation = new TronStation(tronWeb);
const newTronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
tronStation.setTronWeb(tronWeb);
APIs
TronStation-SDK provides three parts of calculators and some of utils can be used easily to estimate energy, bandwidth and super representatives data.
There are also some sample usages provided in test directory.
Energy Calculators
const res = await tronStation.energy.trx2FrozenEnergy(1);
const res = await tronStation.energy.trx2FrozenEnergy(10e5, { unit: 'sun' });
const res = await tronStation.energy.frozenEnergy2Trx(666.74484);
const res = await tronStation.energy.frozenEnergy2Trx(666.74484, { unit: 'sun' });
const res = await tronStation.energy.trx2BurnedEnergy(1);
const res = await tronStation.energy.trx2BurnedEnergy(10e5, { unit: 'sun' });
const res = await tronStation.energy.burnedEnergy2Trx(10e4);
const res = await tronStation.energy.burnedEnergy2Trx(10e4, { unit: 'sun' });
const res = await tronStation.energy.getMaxEnergyLimit('your hex address', 1000);
Bandwidth Calculators
const res = await tronStation.bp.trx2FrozenBandwidth(1);
const res = await tronStation.bp.trx2FrozenBandwidth(10e5, { unit: 'sun' });
const res = await tronStation.bp.frozenBandwidth2Trx(7300.356788039041);
const res = await tronStation.bp.frozenBandwidth2Trx(7300.356788039041, { unit: 'sun' });
const res = await tronStation.bp.getAccountBandwidth('4165519569C1A1E81646902142DD56A791DEBCB0D8');
Super Representatives Calculators
const res = await tronStation.witness.calculateSrReward(1000, '41928c9af0651632157ef27a2cf17ca72c575a4d21');
const res = await tronStation.witness.calculateSrReward(1000);
const res = await tronStation.witness.getSrVoteRewardList();
Other tools
const res = await tronStation.apis.fromTrx(1);
const res = await tronStation.apis.toTrx(10e5);
const res = await tronStation.apis.getResourceByName('EnergyWeight');
const res = await tronStation.apis.getResourcesByName(['TotalNetLimit', 'TotalNetWeight']);
const res = await tronStation.apis.getChainParameterByName('getEnergyFee');
const res = await tronStation.apis.getChainParametersByName(['getTotalEnergyCurrentLimit', 'getEnergyFee']);