Appearance
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
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
apikey | string | Yes | Your API key (contact support to obtain) | kvk8wjxxxxR@yaxxyng1 |
address | string | Yes | Address to receive energy | TVbvtCxxxxxxxxxEANBX3izF9b |
value | string | Yes | Number of transactions (65,000 energy per transaction) | 1 |
Request Example
GET https://api.trxenergy.cc/user/getEnergy?apikey=kvk8wjxxxxR@yaxxyng1&address=TVbvtCxxxxxxxxxEANBX3izF9b&value=1Response Parameters
Success Response
json
{
"msg": null,
"code": 200,
"data": {
"amount": "3.50",
"balance": "12.50",
"txid": "9f5a8047exxxxxb04215fd399c"
}
}Response Fields
| Parameter | Type | Description | Example |
|---|---|---|---|
code | int | 200 for success, others for failure | 200 |
msg | string | Message information | "Insufficient balance" |
data.amount | string | Cost amount for this transaction (TRX) | "3.50" |
data.balance | string | Remaining balance (TRX) | "12.50" |
data.txid | string | Transaction hash | "9f5a8047exxxxxb04215fd399c" |
Error Response
json
{
"msg": "Insufficient balance",
"code": 1002,
"data": null
}Status Codes
| Code | Description |
|---|---|
| 200 | Success |
| 1000 | Parameter is empty |
| 1001 | Account does not exist |
| 1002 | Insufficient balance |
| 2001 | Blockchain exception |
| 2002 | System exception |
| 2003 | Address exception or not activated |
Energy Consumption Reference
Transaction Energy Requirements
| Transaction Type | Energy Per Transaction | Equivalent TRX |
|---|---|---|
| Standard transaction | 65,000 energy | ~13.4 TRX |
| New address activation | 131,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
Parameter is empty (Code: 1000)
Error: Parameter is empty Solution: Ensure all required parameters (apikey, address, value) are providedAccount does not exist (Code: 1001)
Error: Account does not exist Solution: Verify your API key is correct and account is activeInsufficient balance (Code: 1002)
Error: Insufficient balance Solution: Top up your account with TRXAddress exception or not activated (Code: 2003)
Error: Address exception or not activated Solution: Ensure the TRON address is valid and activatedBlockchain exception (Code: 2001)
Error: Blockchain exception Solution: Temporary network issue, please try again laterSystem exception (Code: 2002)
Error: System exception Solution: Server maintenance, please try again later
