Skip to content

SDK Libraries ​

TronZap provides official SDK libraries for multiple programming languages to help you easily integrate with our API. These SDKs handle authentication, API calls, and error handling, allowing you to focus on building your application.

Available SDKs ​

We currently offer SDKs for the following languages:

PHP SDK ​

bash
composer require tron-energy-market/tronzap-sdk-php

View PHP SDK on GitHub

Node.js SDK ​

This SDK is designed to work across multiple JavaScript/TypeScript platforms:

  • Node.js: v16.0.0 or higher
  • Bun: v1.0.0 or higher
  • Deno: v1.0.0 or higher
bash
npm install tronzap-sdk
# or
yarn add tronzap-sdk
# or
pnpm add tronzap-sdk

View Node.js SDK on GitHub

Python SDK ​

bash
pip install tronzap-sdk

View Python SDK on GitHub

Go SDK ​

Requirements: Go 1.21 or higher, no third-party dependencies.

bash
go get github.com/tron-energy-market/tronzap-sdk-go

View Go SDK on GitHub

Java SDK ​

Requirements: Java 17 or higher.

xml
<dependency>
    <groupId>com.tronzap</groupId>
    <artifactId>tronzap-java</artifactId>
    <version>1.0.0</version>
</dependency>
kotlin
implementation("com.tronzap:tronzap-java:1.0.0")

View Java SDK on GitHub

.NET (C#) SDK ​

Requirements: .NET 8 or higher.

bash
dotnet add package Tronzap.Sdk

View .NET SDK on GitHub

Ruby SDK ​

Requirements: Ruby 3.3 or higher.

ruby
# Add the gem to your Gemfile
gem "tronzap-sdk"
bash
# or install it directly
gem install tronzap-sdk

View Ruby SDK on GitHub

Rust SDK ​

Requirements: Rust 1.85 or higher, a Tokio runtime.

toml
[dependencies]
tronzap-sdk = "1.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

View Rust SDK on GitHub

Basic Usage ​

All SDKs provide a similar interface for interacting with the TronZap API. Here are some basic examples:

php
<?php
use TronZap\Client;
use TronZap\Exception\TronZapException;

// Initialize the client
$apiToken = 'your_api_token';
$apiSecret = 'your_api_secret';
$client = new Client($apiToken, $apiSecret);

try {
    // Get available services
    $services = $client->getServices();

    // Create an energy transaction
    $transaction = $client->createEnergyTransaction(
        'TRX_ADDRESS', // TRON wallet address
        65000,         // Energy amount
        1,             // Duration (hours)
        'my-tx-id',    // External ID (optional)
        false          // Don't activate address (optional)
    );

    // Check transaction status
    $status = $client->checkTransaction($transaction['result']['transaction_id']);

} catch (TronZapException $e) {
    echo "Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")\n";
}
javascript
import { TronZapClient, TronZapError } from 'tronzap-sdk';

// Initialize the client
const client = new TronZapClient({
  apiToken: 'your_api_token',
  apiSecret: 'your_api_secret'
});

async function main() {
  try {
    // Get available services
    const services = await client.getServices();
    console.log(services);

    // Create energy transaction
    const transaction = await client.createEnergyTransaction(
      'TRON_WALLET_ADDRESS',
      65150,
      1,
      'my-tx-id',  // Optional external ID
      true        // Optional: activate address if needed
    );
    console.log(transaction);

    // Check transaction status
    const status = await client.checkTransaction(transaction.result.transaction_id);
    console.log(status);

  } catch (error) {
    if (error instanceof TronZapError) {
      console.error(`TronZap API Error: ${error.message} (Code: ${error.code})`);
    } else {
      // Type check the error before accessing its properties
      if (error instanceof Error) {
        console.error(`General error: ${error.message}`);
      } else {
        console.error('An unknown error occurred:', error);
      }
    }
  }
}

main();
python
from tronzap_sdk import TronZapClient, TronZapError

# Initialize the client
api_token = 'your_api_token'
api_secret = 'your_api_secret'
client = TronZapClient(api_token, api_secret)

try:
    # Get available services
    services = client.get_services()

    # Create an energy transaction
    transaction = client.create_energy_transaction(
        address='TRX_ADDRESS',  # TRON wallet address
        energy_amount=65000,    # Energy amount
        duration=1,             # Duration (hours)
        external_id='my-tx-id', # External ID (optional)
        activate_address=False  # Don't activate address (optional)
    )

    # Check transaction status
    status = client.check_transaction(transaction['result']['transaction_id'])

except TronZapError as e:
    print(f"Error: {e.message} (Code: {e.code})")
go
package main

import (
	"context"
	"errors"
	"fmt"
	"log"

	tronzap "github.com/tron-energy-market/tronzap-sdk-go"
)

func main() {
	// Initialize the client
	client := tronzap.NewClient("your_api_token", "your_api_secret")
	ctx := context.Background()

	// Get available services
	services, err := client.GetServices(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", services)

	// Create an energy transaction
	tx, err := client.CreateEnergyTransaction(ctx, tronzap.EnergyTransactionRequest{
		Address:         "TRX_ADDRESS", // TRON wallet address
		Energy:          65000,         // Energy amount
		Duration:        1,             // Duration (hours)
		ExternalID:      "my-tx-id",    // External ID (optional)
		ActivateAddress: false,         // Don't activate address (optional)
	})
	var apiErr *tronzap.APIError
	if errors.As(err, &apiErr) {
		log.Fatalf("Error: %s (Code: %d)", apiErr.Message, apiErr.Code)
	} else if err != nil {
		log.Fatal(err)
	}

	// Check transaction status
	status, err := client.CheckTransaction(ctx, tronzap.CheckTransactionRequest{ID: tx.ID})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(status.Status)
}
java
import com.tronzap.sdk.TronzapClient;
import com.tronzap.sdk.exception.ApiException;
import com.tronzap.sdk.exception.TronzapException;
import com.tronzap.sdk.request.CheckTransactionRequest;
import com.tronzap.sdk.request.EnergyTransactionRequest;
import com.tronzap.sdk.response.Services;
import com.tronzap.sdk.response.Transaction;

public class Example {
    public static void main(String[] args) {
        // Initialize the client
        TronzapClient client = TronzapClient.builder()
                .apiToken("your_api_token")
                .apiSecret("your_api_secret")
                .build();

        try {
            // Get available services
            Services services = client.getServices();
            System.out.println(services);

            // Create an energy transaction
            Transaction tx = client.createEnergyTransaction(
                    EnergyTransactionRequest.builder("TRX_ADDRESS", 65000) // TRON wallet address, Energy amount
                            .duration(1)              // Duration (hours)
                            .externalId("my-tx-id")   // External ID (optional)
                            .activateAddress(false)   // Don't activate address (optional)
                            .build());

            // Check transaction status
            Transaction status = client.checkTransaction(CheckTransactionRequest.byId(tx.id()));
            System.out.println(status.status());

        } catch (ApiException e) {
            System.err.println("Error: " + e.getMessage() + " (Code: " + e.getCode() + ")");
        } catch (TronzapException e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
}
csharp
using Tronzap.Sdk;
using Tronzap.Sdk.Exceptions;
using Tronzap.Sdk.Requests;
using Tronzap.Sdk.Responses;

// Initialize the client
var client = new TronzapClient(new TronzapClientOptions
{
    ApiToken = "your_api_token",
    ApiSecret = "your_api_secret",
});

try
{
    // Get available services
    ServiceRates services = await client.GetServicesAsync();
    Console.WriteLine(services);

    // Create an energy transaction
    Transaction tx = await client.CreateEnergyTransactionAsync(new EnergyTransactionRequest
    {
        Address = "TRX_ADDRESS",   // TRON wallet address
        Energy = 65000,            // Energy amount
        Duration = 1,              // Duration (hours)
        ExternalId = "my-tx-id",   // External ID (optional)
        ActivateAddress = false,   // Don't activate address (optional)
    });

    // Check transaction status
    Transaction status = await client.CheckTransactionAsync(CheckTransactionRequest.ById(tx.Id));
    Console.WriteLine(status.Status);
}
catch (TronzapApiException e)
{
    Console.Error.WriteLine($"Error: {e.Message} (Code: {e.Code})");
}
catch (TronzapException e)
{
    Console.Error.WriteLine($"Error: {e.Message}");
}
ruby
require "tronzap"

# Initialize the client
client = Tronzap::Client.new(
  api_token: "your_api_token",
  api_secret: "your_api_secret"
)

begin
  # Get available services
  services = client.get_services
  p services

  # Create an energy transaction
  transaction = client.create_energy_transaction(
    address: "TRX_ADDRESS",   # TRON wallet address
    energy: 65000,            # Energy amount
    duration: 1,              # Duration (hours)
    external_id: "my-tx-id",  # External ID (optional)
    activate_address: false   # Don't activate address (optional)
  )

  # Check transaction status
  status = client.check_transaction(id: transaction.id)
  puts status.status
rescue Tronzap::ApiError => e
  warn "Error: #{e.message} (Code: #{e.code})"
rescue Tronzap::Error => e
  warn "Error: #{e.message}"
end
rust
use tronzap_sdk::requests::{CheckTransactionRequest, EnergyTransactionRequest};
use tronzap_sdk::{TronzapClient, TronzapError};

async fn run() -> Result<(), TronzapError> {
    // Initialize the client
    let client = TronzapClient::new("your_api_token", "your_api_secret")?;

    // Get available services
    let services = client.get_services().await?;
    println!("{services:?}");

    // Create an energy transaction
    let request = EnergyTransactionRequest::new("TRX_ADDRESS", 65000) // TRON wallet address, Energy amount
        .duration(1)                // Duration (hours)
        .external_id("my-tx-id")    // External ID (optional)
        .activate_address(false);   // Don't activate address (optional)
    let tx = client.create_energy_transaction(&request).await?;

    // Check transaction status
    let status = client
        .check_transaction(&CheckTransactionRequest::by_id(tx.id))
        .await?;
    println!("{}", status.status);
    Ok(())
}

#[tokio::main]
async fn main() {
    match run().await {
        Ok(()) => {}
        Err(TronzapError::Api(e)) => {
            eprintln!("Error: {} (Code: {:?})", e.message(), e.code())
        }
        Err(e) => eprintln!("Error: {e}"),
    }
}

Features ​

All our SDKs provide the following features:

  • Authentication: Automatic generation of API signatures for secure requests
  • Services Info: Get available services and pricing
  • Energy Transactions: Create transactions for energy purchase
  • Bandwidth & Resource Bundles: Buy bandwidth, or energy and bandwidth in one transaction
  • Energy Estimation & Address Info: Estimate energy for a USDT transfer and get address resources and balances
  • AML Checks: Screen addresses and transactions for risk
  • Address Activation: Create transactions for address activation
  • Transaction Status: Check the status of your transactions
  • Account Management: Get account balance and usage information

Documentation ​

For complete documentation on each SDK, please refer to their respective GitHub repositories.

Tron Energy API Documentation