SDK Libraries

TronsaveSDK is a TypeScript library that helps you easily interact with the Tronsave API to manage resources (ENERGY/BANDWIDTH) on the TRON blockchain. This SDK provides robust, strongly-typed functions and can be integrated into modern backend systems.

Node.js SDK

Supports Node.js v18.0.0 or higher.

npm install tronsave-sdk

or

yarn add tronsave-sdk

Basic Usage

Example:

import { TronsaveSDK } from "tronsave-sdk";

const main = async () => {
    const apiKey = "your_api_key";
    const sdk = new TronsaveSDK({ network: "testnet", apiKey });
    const userInfo = await sdk.getUserInfo();
    console.log(userInfo);
    // Example: Estimate cost for 32,000 ENERGY units for 1 hour
    const estimate = await sdk.estimateBuyResource({
        receiver: "TAk6jzZqHwNUkUcbvMyAE1YAoUPk7r2T6h",
        resourceType: "ENERGY",
        durationSec: 3600, // 1 hour
        resourceAmount: 32000,
    });
    console.log(estimate);
    if (estimate.estimateTrx > Number(userInfo.balance)) throw new Error("Insufficient balance");
    const { orderId } = await sdk.buyResource({
        receiver: "TAk6jzZqHwNUkUcbvMyAE1YAoUPk7r2T6h",
        resourceType: "ENERGY",
        durationSec: 3600, // 1 hour
        resourceAmount: 32000,
    });
    console.log(`Buy resource success -> orderId: ${orderId}`);
    // Wait for 5 seconds for the order to be filled
    console.log("Waiting for 5 seconds for the order to be filled...");
    await new Promise((resolve) => setTimeout(resolve, 5000));
    const order = await sdk.getOrder(orderId);
    console.log(order);
    if (order.fulfilledPercent < 100) console.log("Order is not filled");
    else console.log("Order is filled");
};

main();

Features

All our SDKs provide the following features:

  • Buy Resource: Buy resources

  • Estimate Buy Resource: Estimate resource purchase cost

  • Extend Request: Extend resource requests

  • Get Extendable Delegates: Get the list of extendable delegates

  • Get User Info: Fetch user information

  • Get Order, Get Orders: Fetch order details

  • Get Order Book: Get order book

Last updated