@magnaflow/tronsave
v1.0.2
Published
TRON energy rental service (TronSave) SDK
Maintainers
Readme
@magnaflow/tronsave
Helpers for integrating with the TronSave resource rental API.
What It Provides
- Mainnet and testnet TronSave config resolution
- Estimate requests for energy and bandwidth purchase cost
- Signed TRX transfer transaction construction
- Order creation helpers for the TronSave HTTP API
Install
npm install @magnaflow/tronsaveKey Exports
TRONSAVE_MAINNETTRONSAVE_TESTNETgetTronSaveConfigtronsaveGetEstimatetronsaveGetSignedTransactiontronsaveCreateOrderTronSaveConfigTronSaveEstimateParamsTronSaveCreateOrderParams
Example
import { TronWeb } from 'tronweb';
import {
getTronSaveConfig,
tronsaveCreateOrder,
tronsaveGetEstimate,
tronsaveGetSignedTransaction,
} from '@magnaflow/tronsave';
const config = getTronSaveConfig({
chain: 'tron',
rest_url: 'https://api.trongrid.io',
});
const estimate = await tronsaveGetEstimate(config, {
resourceAmount: 1000,
durationSec: 86400,
});
const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io' });
const signedTx = await tronsaveGetSignedTransaction(
config,
tronWeb,
estimate.data!.estimateTrx,
'TYourAddress...',
);
await tronsaveCreateOrder(config, {
resourceAmount: 1000,
signedTx,
receiverAddress: 'TYourAddress...',
unitPrice: estimate.data!.unitPrice,
durationSec: 86400,
});Development
bunx nx run tronsave:lint
bunx nx run tronsave:test
bunx nx run tronsave:buildLicense
This package is part of the merchant-v2-sdk monorepo and is covered by the root MIT license.
See ../../LICENSE for details.
