# 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**.

```bash
npm install tronsave-sdk
```

or

```bash
yarn add tronsave-sdk
```

### [View Tronsave SDK npm](https://www.npmjs.com/package/tronsave-sdk)

## Basic Usage <a href="#basic-usage" id="basic-usage"></a>

*Example:*

{% tabs %}
{% tab title="Node.js" %}

```javascript
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();
```

{% endtab %}
{% endtabs %}

## Features <a href="#features" id="features"></a>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tronsave.io/developer/sdk-libraries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
