Skip to content

Create Transaction

Creates a new transaction for energy or bandwidth purchase, resource bundle, or address activation.

A resource bundle allows you to purchase both energy and bandwidth in a single API request.

POST /v1/transaction/new

Request

Request Parameters

FieldTypeRequiredDescription
external_idstringNoOptional external transaction identifier
servicestringYesService type: "energy", "bandwidth", "resource_bundle", or "activate_address"
paramsobjectYesService parameters object
params.addressstringYesTRON wallet address (34 characters)
params.amount*integerConditionalAmount of energy or bandwidth to purchase. Required when service="energy" or "bandwidth" and params.amounts is not provided.
params.energy_amount*integerNoDeprecated. Use params.amount or params.amounts.energy.
params.amounts*objectConditionalResource amounts object. Required when service="resource_bundle". Can also be used for "energy" and "bandwidth" services.
params.amounts.energyintegerConditionalAmount of energy to purchase. Required inside amounts for "resource_bundle".
params.amounts.bandwidthintegerConditionalAmount of bandwidth to purchase. Required inside amounts for "resource_bundle".
params.durationintegerYesDuration in hours. Currently only 1 hour is supported for energy, bandwidth, and resource_bundle.
params.activate_addressbooleanNoWhether to activate the address. Optional for energy, bandwidth, and resource_bundle services.

* We recommend using the amounts object as the most universal approach. The API resolves the resource amount in the following order: params.amountsparams.amountparams.energy_amount.

bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "external_id": "my-external-id-123",
  "service": "energy",
  "params": {
    "address": "TRX_ADDRESS",
    "amounts": {
      "energy": 65000
    },
    "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/transaction/new" \
  -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({
  external_id: 'my-external-id-123',
  service: 'energy',
  params: {
    address: 'TRX_ADDRESS',
    amounts: {
      energy: 65000
    },
    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/transaction/new',
  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([
  'external_id' => 'my-external-id-123',
  'service' => 'energy',
  'params' => [
    'address' => 'TRX_ADDRESS',
    'amounts' => [
      'energy' => 65000
    ],
    'duration' => 1
  ]
]);

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

// Make API request
$ch = curl_init('https://api.tronzap.com/v1/transaction/new');
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({
  'external_id': 'my-external-id-123',
  'service': 'energy',
  'params': {
    'address': 'TRX_ADDRESS',
    'amounts': {
      'energy': 65000
    },
    '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/transaction/new',
  headers=headers,
  data=request_body
)

print(response.json())

Example Request for Resource Bundle

bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "external_id": "my-external-id-123",
  "service": "resource_bundle",
  "params": {
    "address": "TRX_ADDRESS",
    "amounts": {
      "energy": 65000,
      "bandwidth": 345
    },
    "duration": 1,
    "activate_address": true
  }
}'

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

# Make API request
curl -X POST "https://api.tronzap.com/v1/transaction/new" \
  -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({
  external_id: 'my-external-id-123',
  service: 'resource_bundle',
  params: {
    address: 'TRX_ADDRESS',
    amounts: {
      energy: 65000,
      bandwidth: 5000
    },
    duration: 1,
    activate_address: true
  }
});

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

// Make API request
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/transaction/new',
  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([
  'external_id' => 'my-external-id-123',
  'service' => 'resource_bundle',
  'params' => [
    'address' => 'TRX_ADDRESS',
    'amounts' => [
      'energy' => 65000,
      'bandwidth' => 5000
    ],
    'duration' => 1,
    'activate_address' => true
  ]
]);

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

// Make API request
$ch = curl_init('https://api.tronzap.com/v1/transaction/new');
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({
  'external_id': 'my-external-id-123',
  'service': 'resource_bundle',
  'params': {
    'address': 'TRX_ADDRESS',
    'amounts': {
      'energy': 65000,
      'bandwidth': 5000
    },
    'duration': 1,
    'activate_address': True
  }
})

# 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/transaction/new',
  headers=headers,
  data=request_body
)

print(response.json())

Example Request for Address Activation

bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "external_id": "my-external-id-123",
  "service": "activate_address",
  "params": {
    "address": "TRX_ADDRESS"
  }
}'

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

# Make API request
curl -X POST "https://api.tronzap.com/v1/transaction/new" \
  -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({
  external_id: 'my-external-id-123',
  service: 'activate_address',
  params: {
    address: 'TRX_ADDRESS'
  }
});

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

// Make API request
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/transaction/new',
  headers: {
    'Authorization': `Bearer ${apiToken}`,
    'X-Signature': signature,
    'Content-Type': 'application/json'
  },
  data: requestBody
})
.then(response => console.log(response.data))
.catch(error => console.error(error));

Response

The response provides details about the created transaction.

Response Fields

FieldTypeDescription
codeintegerResponse code (0 = success)
request_idstringUnique request identifier
resultobjectResponse data
result.idstringInternal transaction ID
result.external_idstring|nullExternal transaction ID (if provided)
result.servicestringService type: "energy", "bandwidth", "resource_bundle", or "activate_address"
result.paramsobjectOriginal request parameters
result.params.activate_addressbooleanWhether address activation was requested
result.statusstringTransaction status (see status list)
result.amountfloatTransaction amount
result.created_atstringCreation timestamp (ISO 8601 format)
result.hashstringTransaction hash (if completed)

Example Response

json
{
    "code": 0,
    "request_id": "bbf74bcd-fb36-4df8-adc8-25f2bacd087b",
    "result": {
        "id": "transaction_id",
        "external_id": "my-external-id-123",
        "service": "energy",
        "params": {
            "address": "TRX_ADDRESS",
            "amounts": {
                "energy": 65000
            },
            "duration": 1,
            "activate_address": false
        },
        "status": "success",
        "amount": 8.25,
        "created_at": "2024-03-22T12:00:00Z",
        "hash": "transaction_hash"
    }
}

Possible Errors

Error CodeKeyDescription
1authAuthentication error (incorrect token or signature)
2invalid_service_or_paramsInvalid service or parameters
5wallet_not_foundWallet not found
6insufficient_fundsInsufficient funds
10invalid_tron_addressInvalid TRON address
11invalid_energy_amountInvalid energy amount
12invalid_durationInvalid duration
50invalid_bandwidth_amountInvalid bandwidth amount
24address_not_activatedAddress not activated
25address_already_activatedAddress already activated
35service_unavailableService not available
500internal_server_errorInternal server error

Tron Energy API Documentation