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

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
        32000,         // 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=32000,    # 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})")

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
  • 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