Skip to content

API Call - Request Energy

Interface Description

This interface allows you to rent energy for specified TRON addresses to reduce TRX consumption costs for on-chain transactions.

API Information

  • Endpoint: https://api.trxenergy.cc/user/getEnergy
  • Method: GET
  • Content-Type: application/json
  • Encoding: UTF-8

Request Parameters

URL Parameters

ParameterTypeRequiredDescriptionExample
apikeystringYesYour API key (contact support to obtain)kvk8wjxxxxR@yaxxyng1
addressstringYesAddress to receive energyTVbvtCxxxxxxxxxEANBX3izF9b
valuestringYesNumber of transactions (65,000 energy per transaction)1

Request Example

GET https://api.trxenergy.cc/user/getEnergy?apikey=kvk8wjxxxxR@yaxxyng1&address=TVbvtCxxxxxxxxxEANBX3izF9b&value=1

Response Parameters

Success Response

json
{
    "msg": null,
    "code": 200,
    "data": {
        "amount": "3.50",
        "balance": "12.50",
        "txid": "9f5a8047exxxxxb04215fd399c"
    }
}

Response Fields

ParameterTypeDescriptionExample
codeint200 for success, others for failure200
msgstringMessage information"Insufficient balance"
data.amountstringCost amount for this transaction (TRX)"3.50"
data.balancestringRemaining balance (TRX)"12.50"
data.txidstringTransaction hash"9f5a8047exxxxxb04215fd399c"

Error Response

json
{
    "msg": "Insufficient balance",
    "code": 1002,
    "data": null
}

Status Codes

CodeDescription
200Success
1000Parameter is empty
1001Account does not exist
1002Insufficient balance
2001Blockchain exception
2002System exception
2003Address exception or not activated

Energy Consumption Reference

Transaction Energy Requirements

Transaction TypeEnergy Per TransactionEquivalent TRX
Standard transaction65,000 energy~13.4 TRX
New address activation131,000 energy (2 transactions)~26.5 TRX

Note: Each "transaction" (value=1) provides 65,000 energy. For new address activation, you need to request 2 transactions (value=2).

SDK Examples

JavaScript/Node.js

javascript
const axios = require('axios');

async function rentEnergy(apikey, address, value) {
    try {
        const url = `https://api.trxenergy.cc/user/getEnergy?apikey=${apikey}&address=${address}&value=${value}`;
        const response = await axios.get(url);
        
        if (response.data.code === 200) {
            console.log('Rental successful:', response.data);
            console.log(`Cost: ${response.data.data.amount} TRX`);
            console.log(`Remaining balance: ${response.data.data.balance} TRX`);
            console.log(`Transaction hash: ${response.data.data.txid}`);
            return response.data;
        } else {
            console.error('Rental failed:', response.data.msg);
            throw new Error(response.data.msg);
        }
    } catch (error) {
        console.error('Request failed:', error.message);
        throw error;
    }
}

// Usage example
rentEnergy('kvk8wjxxxxR@yaxxyng1', 'TVbvtCxxxxxxxxxEANBX3izF9b', '1');

Python

python
import requests

def rent_energy(apikey, address, value):
    url = "https://api.trxenergy.cc/user/getEnergy"
    params = {
        "apikey": apikey,
        "address": address,
        "value": value
    }
    
    try:
        response = requests.get(url, params=params)
        response.raise_for_status()
        data = response.json()
        
        if data['code'] == 200:
            print("Rental successful:", data)
            print(f"Cost: {data['data']['amount']} TRX")
            print(f"Remaining balance: {data['data']['balance']} TRX")
            print(f"Transaction hash: {data['data']['txid']}")
            return data
        else:
            print("Rental failed:", data['msg'])
            raise Exception(data['msg'])
    except requests.exceptions.RequestException as e:
        print("Request failed:", e)
        raise e

# Usage example
rent_energy("kvk8wjxxxxR@yaxxyng1", "TVbvtCxxxxxxxxxEANBX3izF9b", "1")

PHP

php
<?php
function rentEnergy($apikey, $address, $value) {
    $url = "https://api.trxenergy.cc/user/getEnergy";
    $params = http_build_query([
        'apikey' => $apikey,
        'address' => $address,
        'value' => $value
    ]);
    
    $fullUrl = $url . '?' . $params;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $fullUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($httpCode !== 200) {
        throw new Exception("HTTP Error: " . $httpCode);
    }
    
    $data = json_decode($response, true);
    
    if ($data['code'] === 200) {
        echo "Rental successful: " . json_encode($data, JSON_PRETTY_PRINT) . "\n";
        echo "Cost: " . $data['data']['amount'] . " TRX\n";
        echo "Remaining balance: " . $data['data']['balance'] . " TRX\n";
        echo "Transaction hash: " . $data['data']['txid'] . "\n";
        return $data;
    } else {
        echo "Rental failed: " . $data['msg'] . "\n";
        throw new Exception($data['msg']);
    }
}

// Usage example
try {
    $result = rentEnergy('kvk8wjxxxxR@yaxxyng1', 'TVbvtCxxxxxxxxxEANBX3izF9b', '1');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>

cURL Command Line

bash
curl -X GET "https://api.trxenergy.cc/user/getEnergy?apikey=kvk8wjxxxxR@yaxxyng1&address=TVbvtCxxxxxxxxxEANBX3izF9b&value=1"

Error Handling

Common Errors and Solutions

  1. Parameter is empty (Code: 1000)

    Error: Parameter is empty
    Solution: Ensure all required parameters (apikey, address, value) are provided
  2. Account does not exist (Code: 1001)

    Error: Account does not exist
    Solution: Verify your API key is correct and account is active
  3. Insufficient balance (Code: 1002)

    Error: Insufficient balance
    Solution: Top up your account with TRX
  4. Address exception or not activated (Code: 2003)

    Error: Address exception or not activated
    Solution: Ensure the TRON address is valid and activated
  5. Blockchain exception (Code: 2001)

    Error: Blockchain exception
    Solution: Temporary network issue, please try again later
  6. System exception (Code: 2002)

    Error: System exception
    Solution: Server maintenance, please try again later