Tronsave
🇬🇧 English
🇬🇧 English
  • 📗INTRODUCTION
    • What is Tronsave ?
    • Why Tronsave?
  • Buyer
    • How to buy Energy ?
      • Buy on the Website
      • Buy on Telegram
        • 1. Create a Tronsave telegram account
        • 2. How To Deposit TRX
        • 3. Get the Tronsave API Key
        • 4. How to buy on Telegram
    • Extend
      • Quick extend
      • Advance
  • 🏬Seller
    • Get Energy by Staking 2.0
    • Permission
    • Sell Energy
      • Manual Sell
      • Auto Sell
      • Sell Suggestion
  • DEVELOPER
    • Get API key
      • On the Website
      • On Telegram
    • Buy Resources (v2)
      • Use Signed Transaction
        • Estimate TRX
        • Get Signed Transaction
        • Create order
      • Use API Key
        • Get Internal Account Info
        • Get Order Book
        • Estimate TRX
        • Create order
        • Get one order details
        • Get Internal Account Order History
    • Extend Orders (v2)
      • Step 1: Get Extendable Delegates
      • Step 2: Extend Request
    • SDK Libraries
    • Rest API v0
      • Buy on Rest API
        • Use Signed Transaction
          • Estimate TRX
          • Get Signed Transaction
          • Create order
          • Demo
        • Use API Key
          • Get Internal Account Info
          • Get Order Book
          • Estimate of TRX
          • Create order
          • Get one order details
          • Get Internal Account Order History
      • Extend with Rest API
  • 🤝Referrer
    • Referrals
  • 💡FAQ
    • Questions for Energy market
    • Calculate APY in TronSave
    • How to connect wallet in Tronsave?
    • Team of Service
  • 👨‍💻Full Code Example
    • Code Example (v2)
      • Buy Resource by API using private key
      • Buy Resources by API using api key
      • Extend order by API using api key
      • Extend order by API using private key
    • Code Example (v0)
      • Buy energy by API using private key
      • Buy energy by API using api key
      • Extend order by API using api key
Powered by GitBook
On this page
  • Node.js SDK
  • View Tronsave SDK npm
  • Basic Usage
  • Features
  1. DEVELOPER

SDK Libraries

PreviousStep 2: Extend RequestNextRest API v0

Last updated 3 days ago

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

View Tronsave SDK npm