Tronsave
🇬🇧 English
Search
K

Quick Buy Energy TRONSAVE

This is a typical example of integrating fast energy purchase and sending trtions in only 1 setting.

See how to install and config SDK here

// before
const instance = await window.tronWeb.contract(ABI, contractAddress);
const result = await instance
.method("...")
.send({
feeLimit: 1e9,
callValue: 1000000
});
// after use SDK
const options = {
network: "mainnet",
}
const tronSave = new TronSave(window.tronWeb, options);
// Replace window.tronWeb with tronSave
const instance = await tronSave.contract(ABI, contractAddress);
const result = await instance
.method("...")
.send({
feeLimit: 1e9,
callValue: 1000000,
// Add options useEnergy to buy more energy if you don't have enough
useEnergy: true
});

* Tronsave will do all the steps for you:

+ Estimate the energy needed.
+ If you don't have enough energy, TRONSAVE SDK will buy more energy on the TRONSAVE market.
+ Send the transaction.

You only need to sign 2 transactions:

  • Buy energy transaction
  • Original transaction

Extra options for send():

Options
Type
Required
Default
Description
useEnergy
boolean
false
false
set True if you want to buy energy quickly
maxPrice
number
false
The highest price you allow the sdk to buy energy
gapBuy
number
false
0.05% of the estimated energy but cannot exceed 500.
Amount of energy to buy = energy estimated - account energy + gap.
sponsor
string
false
The sponsor of the order buys energy, if available.