The fastest way to buy TRON energy in Java is the official TronSave SDK: add io.tronsave:sdk from Maven Central, create a client with your API key, estimate the cost, and place the order — four typed calls, no raw HTTP. This guide walks through the full integration, from install to tracking a filled order.
Why rent energy from Java code?
Backend services that send USDT (TRC-20) at any volume face the same math as everyone else on TRON: every transfer consumes energy, and energy you don’t have is paid for by burning TRX at protocol rates (see TRON’s resource model). Renting the energy just-in-time before a payout run typically costs a fraction of burning, and doing it from code means your service tops itself up — no human watching a dashboard. If you want the API-level view first, start with our API automation guide; this post is the same flow with Java types instead of raw endpoints.
What is the TronSave Java SDK?
It’s the official Java client, published to Maven Central as io.tronsave:sdk (version 2.0.0, targeting the current v2 API and Java 17+). Alongside it sit official SDKs for TypeScript, Rust, Python, and PHP — all wrapping the same endpoints, per the official SDK documentation.
The Java client is small but production-shaped: results come back as typed records (EstimateBuyResource, Order, UserInfo), errors are a real exception hierarchy (auth, validation, rate-limit, network, business), and the client has a built-in rate limiter plus configurable timeout and retries on its builder.

How do you install it?
Maven (pom.xml):
<dependency>
<groupId>io.tronsave</groupId>
<artifactId>sdk</artifactId>
<version>2.0.0</version>
</dependency>
Gradle (build.gradle):
implementation 'io.tronsave:sdk:2.0.0'
How do you get an API key?
Create one in the TronSave dashboard (see the authentication docs). With the API-key flow, orders are paid from your prepaid TronSave balance — ideal for backend services, since your TRON private key never touches the integration. Develop against Network.TESTNET (the Nile test network, no real TRX), then switch the enum to Network.MAINNET to go live.
How to buy TRON energy in Java, end to end
import io.tronsave.sdk.Network;
import io.tronsave.sdk.TronsaveClient;
import io.tronsave.sdk.model.BuyResourceResult;
import io.tronsave.sdk.model.EstimateBuyResource;
import io.tronsave.sdk.model.Order;
import java.util.Map;
public class BuyEnergy {
public static void main(String[] args) {
TronsaveClient client = TronsaveClient.builder()
.apiKey(System.getenv("TRONSAVE_API_KEY"))
.network(Network.TESTNET) // Network.MAINNET in production
.build();
Map<String, Object> request = Map.of(
"receiver", "TAk6jzZqHwNUkUcbvMyAE1YAoUPk7r2T6h",
"resourceType", "ENERGY",
"resourceAmount", 65_000,
"durationSec", 3_600);
// 1. Estimate before you commit
EstimateBuyResource estimate = client.estimateBuyResource(request);
System.out.println("Estimated cost (TRX): " + estimate.estimateTrx());
// 2. Place the order, paid from your TronSave balance
BuyResourceResult result = client.buyResource(request);
// 3. Track it until the delegation lands
Order order = client.getOrder(result.orderId());
System.out.println(order.status() + " — " + order.fulfilledPercent() + "% filled");
}
}
Three things worth noting. The estimate call returns the unit price and available liquidity as well as the TRX total, so you can gate the purchase on price. The buy returns an orderId immediately — fills are asynchronous, so poll getOrder until status and fulfilledPercent show the delegation you expect. And the example’s 65,000 energy for one hour is sized for a single USDT transfer; scale resourceAmount and durationSec to your batch.
What else can the client do?
| Method | What it does |
|---|---|
getUserInfo() |
Account details and prepaid balance |
estimateBuyResource(...) |
Price a purchase before ordering |
buyResource(...) |
Buy energy or bandwidth |
getOrder(id) / getOrders(page, size) |
Order detail and history |
getOrderBook(...) |
Read current market depth |
getExtendableDelegates(...) / extendRequest(...) |
List and extend active delegations |
The builder also accepts timeoutMs(...), maxRetries(...), and baseUrl(...) for tuning.
How should production code handle errors?
Everything the client throws extends TronsaveException, but the subtypes deserve different treatment. TronsaveValidationException means the request itself is wrong — a malformed receiver address, a bad amount — so retrying is pointless; log it and fix the input. TronsaveRateLimitException means you’re calling faster than your key allows; back off and retry (the client also has an internal rate limiter that smooths bursts before they hit the wire). TronsaveNetworkException covers transient transport failures, the natural fit for the builder’s maxRetries. Auth failures usually mean a missing or revoked key — check the environment variable actually reached the process.
Two habits pay off in payout services specifically: call getUserInfo() at startup and alert when the prepaid balance drops below your next run’s estimated cost, and treat estimateBuyResource as a circuit breaker — if the quoted estimateTrx() jumps past a sanity threshold, hold the run instead of buying into a price spike.
FAQ
Which Java version is required?
Java 17 or newer — the SDK’s models are records, a Java 16+ feature, and the published bytecode targets 17.
Can I test without spending real TRX?
Yes. Network.TESTNET points the client at the Nile test network, where the whole flow works identically with test funds.
Does my TRON private key ever leave my server?
With the API-key flow shown here, it isn’t involved at all — orders are paid from your prepaid TronSave balance. A separate private-key flow exists if you prefer paying directly from a TRON account; see the official code examples.
Can I buy bandwidth too?
Yes — the same buyResource call with "resourceType": "BANDWIDTH".
What about other languages?
Official SDKs exist for TypeScript, Rust, Python, and PHP. We have walkthroughs for TypeScript and Python.
Do I have to use the SDK to buy TRON energy in Java?
No — it wraps the documented v2 HTTP API, so you can call the endpoints directly with any HTTP client. The SDK just saves you the request plumbing, retries, rate limiting, and response typing, which is exactly the code you least want to maintain yourself in a payment path.
Building a payout service? Add io.tronsave:sdk, grab an API key from the TronSave dashboard, and your backend rents its own energy — estimate, buy, track, done.
The TronSave SDK and API are operated by TronSave, the publisher of this blog. Test on Nile before pointing any integration at mainnet funds.
