Skip to content
Tronsave BlogTronsave Blog
  • Tron News
  • Fee Calculator
  • Tron Guidelines
  • Tronsave Intro
  • Tronsave Programs
Buy Energy/Bandwidth
Tronsave BlogTronsave Blog
Buy Energy/Bandwidth
  • Home » 
  • Tron Guidelines

How to Buy TRON Energy with Code: The TronSave SDK (Node.js, Python & More)

By Tronsave July 12, 2026 78 Views

If your app, exchange, or bot sends USDT (TRC-20) at scale, you don’t want to buy energy by hand. The official TronSave SDK lets you estimate, buy, extend and track energy orders straight from your backend — in Node.js, Python, Rust, Java or PHP. This guide gets you from install to your first on-chain energy order.

Table of Contents

The SDKs

All SDKs target the v2 API and wrap the same endpoints, so you get the same operations in every language:

Language Package Install Requires
TypeScript / JS tronsave-sdk npm install tronsave-sdk Node.js 18+
Python tronsave pip install tronsave Python 3.9+
Rust tronsave cargo add tronsave —
Java io.tronsave:sdk Maven / Gradle —
PHP tronsave/sdk composer require tronsave/sdk PHP 8.1+

The Rust, Python, Java and PHP packages are all at 2.0.0. For Java, the coordinates are io.tronsave:sdk:2.0.0 — add it to pom.xml as a dependency or to build.gradle as implementation 'io.tronsave:sdk:2.0.0'.

What every SDK covers

The surface is deliberately small. Whichever language you pick, you get the same seven operations:

  • Estimate Buy Resource — price a purchase before you commit to it.
  • Buy Resource — place the order for Energy or Bandwidth; returns an order ID.
  • Get Order / Get Orders — fetch one order’s status, or your order history.
  • Get Order Book — read live supply as price levels, cheapest first.
  • Get User Info — internal account balance and deposit address.
  • Get Extendable Delegates — list delegations that are eligible to be renewed.
  • Extend Request — renew an existing delegation instead of buying a fresh order.

That last pair matters more than it looks. If a receiver already has energy delegated and you just need it to last longer, extending is the correct call — see the Extend feature guide.

Quickstart (Node.js)

The fastest route is the API-key flow: create an SDK instance, estimate the cost, then place the order. Grab an API key from the TronSave dashboard (see Authentication).

import { TronsaveSDK } from "tronsave-sdk";

const main = async () => {
  const sdk = new TronsaveSDK({ network: "mainnet", apiKey: "your_api_key" });

  const userInfo = await sdk.getUserInfo();

  // Estimate cost for 65,000 ENERGY for 1 hour (one USDT transfer)
  const estimate = await sdk.estimateBuyResource({
    receiver: "TXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    resourceType: "ENERGY",
    durationSec: 3600,
    resourceAmount: 65000,
  });
  if (estimate.estimateTrx > Number(userInfo.balance)) throw new Error("Insufficient balance");

  const { orderId } = await sdk.buyResource({
    receiver: "TXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    resourceType: "ENERGY",
    durationSec: 3600,
    resourceAmount: 65000,
  });

  await new Promise((r) => setTimeout(r, 5000)); // wait ~5s to fill
  const order = await sdk.getOrder(orderId);
  console.log(order.fulfilledPercent < 100 ? "Not filled" : "Filled");
};

main();

Tip: use network: "testnet" (Nile) to develop with no real TRX, then switch to "mainnet" for production.

Two details worth knowing before you run it. userInfo.balance comes back in SUN as a string — 1 TRX is 1,000,000 SUN — which is why the comparison casts it. And durationSec is optional: leave it out and the order defaults to 259,200 seconds, or 3 days.

The same task in Python

The Python package installs with pip install tronsave and exposes the same estimate → buy → track flow; per-language method signatures live in the SDK reference. If you'd rather see exactly which HTTP calls are being made underneath, here is the identical job — estimate, buy, then poll — written against the raw v2 endpoints:

import time, requests

API = "https://api.tronsave.io"          # testnet: https://api-dev.tronsave.io
HEADERS = {"apikey": "your_api_key", "Content-Type": "application/json"}
ORDER = {
    "receiver": "TXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "resourceType": "ENERGY",
    "resourceAmount": 65000,
    "durationSec": 3600,
    "unitPrice": "MEDIUM",
}

estimate = requests.post(f"{API}/v2/estimate-buy-resource", json=ORDER).json()["data"]
print(estimate["estimateTrx"] / 1e6, "TRX", estimate["availableResource"], "available")

order = requests.post(f"{API}/v2/buy-resource", headers=HEADERS,
                      json={**ORDER, "options": {"allowPartialFill": True,
                                                 "maxPriceAccepted": 100}}).json()
order_id = order["data"]["orderId"]

time.sleep(5)
detail = requests.get(f"{API}/v2/order/{order_id}", headers=HEADERS).json()["data"]
print("Filled" if detail["fulfilledPercent"] == 100 else "Not filled")

Same three steps, same field names, same response envelope. The SDK's value is typing and retries, not a different API — so pick whichever your stack prefers. For a fuller Python script with order-book sizing and error branches, see how to buy TRON energy in Python.

Estimate before you buy

The estimate call is worth a paragraph of its own because its response tells you two separate things. estimateTrx is the cost in SUN. availableResource is how much the market can actually supply right now. If availableResource comes back lower than the resourceAmount you asked for, the order cannot fill completely at that moment — and you decide what to do about it through options: allowPartialFill: true to take what's there, or onlyCreateWhenFulfilled: true to refuse anything less than a full match. For retry-heavy bots, preventDuplicateIncompleteOrders: true stops a repeated call from stacking identical open orders.

Errors and limits

Endpoints allow 15 requests per second; exceeding that returns HTTP 429 with "Rate limit reached", and a simple 1s/2s/4s backoff is enough. Application errors arrive as error: true with a machine-readable code inside message — INVALID_API_KEY, INTERNAL_BALANCE_ACCOUNT_TOO_LOW, PRICE_EXCEED_MAX_PRICE_REQUIRED, CANNOT_FULFILLED. Branch on the code; the wording can change.

Driving TronSave from an AI agent

If your integration is an agent rather than a service, TronSave also publishes an MCP server, hosted at https://mcp.tronsave.io/mcp over Streamable HTTP (with https://mcp.tronsave.io/testnet/mcp for the testnet). It exposes 29 MCP tools — tronsave_estimate_buy_resource, tronsave_list_order_books, tronsave_internal_order_create and the rest — with API-key or wallet-signature sessions. Point any MCP-compatible client at the endpoint; our guide to the TronSave MCP server walks through login, the two tool families, and the safety model.

Prefer raw HTTP? The SDKs wrap the same endpoints in the API — see our API automation guide, the breakdown of TronSave order types, and, for high volume, buying energy in bulk.

FAQ

Do I need an API key?
The API-key flow is the simplest; you can also sign with a private key. Get a key from the dashboard. The difference is custody: an API key spends from a prefunded TronSave internal account, while the signed-transaction flow pays from your own wallet on every purchase and needs TronWeb.

Which languages are supported?
Node.js/TypeScript, Python, Rust, Java and PHP — all on the v2 API. Language-specific walkthroughs are available for Python, Java, PHP, and Rust.

How much energy per USDT transfer?
About 65,000 (≈130,000 if the recipient has never held USDT). More detail in how much energy a USDT transfer needs.

Can I test without spending real TRX?
Yes. Set network: "testnet" (or point the base URL at https://api-dev.tronsave.io) to run against Nile. Keys, balances and orders are separate per environment, so issue a Nile key at testnet.tronsave.io — a mainnet key will be rejected. Shasta is not supported.

Start building: read the TronSave docs and grab an API key on the market dashboard.

Python dev? See the language-specific walkthrough: how to buy TRON energy in Python (full runnable script).

Rate this post
Share
facebookShare on FacebooktwitterShare on TwitterpinterestShare on Pinterest
linkedinShare on LinkedinvkShare on VkredditShare on ReddittumblrShare on TumblrviadeoShare on ViadeobufferShare on BufferpocketShare on PocketwhatsappShare on WhatsappviberShare on ViberemailShare on EmailskypeShare on SkypediggShare on DiggmyspaceShare on MyspacebloggerShare on Blogger YahooMailShare on Yahoo mailtelegramShare on TelegramMessengerShare on Facebook Messenger gmailShare on GmailamazonShare on AmazonSMSShare on SMS

Tronsave

Tronsave is a groundbreaking solution on the TRON Stake 2.0 platform, significantly reducing transaction fees in the TRON ecosystem while ensuring absolute security and reliability. With Tronsave, users can save costs, seamlessly purchase energy & bandwidth, and earn stable profits. Ranked Top 3 in Tron Hackathon Season 4 and 1st place Builder in Season 5, Tronsave is committed to excellence. Join now to optimize costs and unlock the potential of TRON.

Related Posts

How to Buy TRON Energy with Code: The TronSave SDK (Node.js, Python & More)

Nine Ways to Quietly Overpay for TRON Energy (and How to Stop)

How to Buy TRON Energy with Code: The TronSave SDK (Node.js, Python & More)

Which TronSave Tool Do You Need? A Router for Every Job

How to Buy TRON Energy with Code: The TronSave SDK (Node.js, Python & More)

Buying TRON Energy From a Multisig Wallet: What Works, What Doesn’t

overview

Ready Resources

—/ —
—/ —

24h Recovery

—
—

APY for Seller

—
—

About us

We are in the Top 3 projects of Tron Hackathon Season 4 and won 1st prize Builder in Season 5

News

Common habits that quietly increase the cost of renting TRON energy

Nine Ways to Quietly Overpay for TRON Energy (and How to Stop)

August 26, 2026
Choosing the right TronSave tool for sending, batching, buying or pricing energy

Which TronSave Tool Do You Need? A Router for Every Job

August 26, 2026
Paying for TRON energy from a multisig treasury wallet

Buying TRON Energy From a Multisig Wallet: What Works, What Doesn’t

August 25, 2026
TronSave Telegram alerts for reclaim warnings, low resources and matching orders

TronSave Alerts: Get Pinged Before Energy Runs Out (and Before You Miss an Order)

August 25, 2026
The TronSave internal balance panel, top-up routes and fund history

The TronSave Internal Balance: Gas-Free Orders and How Much to Keep in It

August 24, 2026
Choosing how long to rent TRON energy, from 15 minutes to 30 days

How Long Should You Rent TRON Energy For? Choosing a Duration

August 24, 2026
What a TronSave buyer, provider and API user each expose

Is TronSave Safe? Custody, Permissions, and What You Actually Expose

August 23, 2026

logo suEzPcU3

Tronsave helps TRON users reduce fees, buy energy & bandwidth easily, and earn secure passive income—seamless, reliable, and built on TRON’s advanced Stake 2.0 platform.

Categories

  • Tron News
  • Fee Calculator
  • Tron Guidelines
  • Tronsave Intro
  • Tronsave Programs

Our Services

  • Web Market
  • API Service
  • Telegram Bot
  • Become Provider

Page

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Use

Follow Us

  • Telegram
  • Twitter (𝕏)
  • Linkedin
  • Youtube
Copyright © 2023 TRONSAVE. All rights reserved.
Back to Top
Menu
  • Tron News
  • Fee Calculator
  • Tron Guidelines
  • Tronsave Intro
  • Tronsave Programs