Skip to content

Calculate Resource Cost

This endpoint calculates the cost of resource purchase without creating a transaction.

POST /v1/calculate

Request

Request Parameters

FieldTypeRequiredDescription
addressstringYesTRON wallet address (34 characters)
amountintegerYesAmount of energy or bandwidth to purchase (minimum 50000 for energy, 1000 for bandwidth)
energyintegerNoDeprecated. Use amount.
durationintegerYesDuration in hours. Currently only 1 hour is supported.
typestringNoResource type to calculate, either "energy" (default) or "bandwidth"
bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "address": "TRX_ADDRESS",
  "amount": 50000,
  "duration": 1
}'

# Calculate signature
SIGNATURE=$(echo -n "${REQUEST_BODY}${API_SECRET}" | sha256sum | cut -d' ' -f1)

# Make API request
curl -X POST "https://api.tronzap.com/v1/calculate" \
  -H "Authorization: Bearer ${API_TOKEN}" \
  -H "X-Signature: ${SIGNATURE}" \
  -H "Content-Type: application/json" \
  -d "${REQUEST_BODY}"
javascript
const crypto = require('crypto');
const axios = require('axios');

const apiToken = 'your_api_token';
const apiSecret = 'your_api_secret';
const requestBody = JSON.stringify({
  address: 'TRX_ADDRESS',
  amount: 50000,
  duration: 1
});

// Calculate signature
const signature = crypto
  .createHash('sha256')
  .update(requestBody + apiSecret)
  .digest('hex');

// Make API request
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/calculate',
  headers: {
    'Authorization': `Bearer ${apiToken}`,
    'X-Signature': signature,
    'Content-Type': 'application/json'
  },
  data: requestBody
})
.then(response => console.log(response.data))
.catch(error => console.error(error));
php
<?php
$apiToken = 'your_api_token';
$apiSecret = 'your_api_secret';
$requestBody = json_encode([
  'address' => 'TRX_ADDRESS',
  'amount' => 50000,
  'duration' => 1
]);

// Calculate signature
$signature = hash('sha256', $requestBody . $apiSecret);

// Make API request
$ch = curl_init('https://api.tronzap.com/v1/calculate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer ' . $apiToken,
  'X-Signature: ' . $signature,
  'Content-Type: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
python
import hashlib
import json
import requests

api_token = 'your_api_token'
api_secret = 'your_api_secret'
request_body = json.dumps({
  'address': 'TRX_ADDRESS',
  'amount': 50000,
  'duration': 1
})

# Calculate signature
signature = hashlib.sha256((request_body + api_secret).encode()).hexdigest()

# Make API request
headers = {
  'Authorization': f'Bearer {api_token}',
  'X-Signature': signature,
  'Content-Type': 'application/json'
}

response = requests.post(
  'https://api.tronzap.com/v1/calculate',
  headers=headers,
  data=request_body
)

print(response.json())

Response

The response provides detailed calculation information for the energy or bandwidth purchase.

Response Fields

FieldTypeDescription
codeintegerResponse code (0 = success)
request_idstringUnique request identifier
resultobjectResponse data
result.addressstringThe TRON address provided in the request
result.typestringResource type ("energy" or "bandwidth")
result.amountintegerThe energy or bandwidth amount provided in the request
result.energyintegerDeprecated. Use result.amount.
result.durationintegerThe duration in hours provided in the request
result.pricefloatTotal price for the energy purchase
result.activation_feefloatPrice for address activation (if required)
result.totalfloatFinal price including activation if required

Example Response``

json
{
    "code": 0,
    "request_id": "bbf74bcd-fb36-4df8-adc8-25f2bacd087b",
    "result": {
        "address": "TRX_ADDRESS",
        "type": "energy",
        "amount": 50000,
        "energy": 50000,
        "duration": 1,
        "price": 1.67,
        "activation_fee": 0,
        "total": 1.67
    }
}

Example Response (Address not activated)

json
{
    "code": 0,
    "request_id": "bbf74bcd-fb36-4df8-adc8-25f2bacd087b",
    "result": {
        "address": "TRX_ADDRESS",
        "type": "energy",
        "amount": 50000,
        "energy": 50000,
        "duration": 1,
        "price": 3.67,
        "activation_fee": 1.4,
        "total": 5.07
    }
}

Possible Errors

Error CodeKeyDescription
1authAuthentication error (incorrect token or signature)
10invalid_tron_addressInvalid TRON address
11invalid_energy_amountInvalid energy amount
12invalid_durationInvalid duration
35service_unavailableService not available
500internal_server_errorInternal server error

Notes

  • The energy amount must be at least 50000.
  • Currently only 1-hour duration is supported.
  • This endpoint only calculates the cost without creating a transaction.
  • To create an actual energy purchase transaction, use the Create Transaction endpoint.

Tron Energy API Documentation