Authentication
All API requests to the TronZap API require authentication using a Bearer token and signature. This ensures the security and integrity of your API requests.
Obtaining API Credentials
To get started with the TronZap API, you'll need to obtain your API credentials from the dashboard:
- Log in to your TronZap Dashboard
- Navigate to the API section
- Copy your API token and secret
TIP
Keep your API credentials secure and never share them publicly. Your API secret should be treated like a password.
Required Headers
Header | Description |
---|---|
Authorization: Bearer YOUR_API_TOKEN | Your API token |
X-Signature: YOUR_SIGNATURE | Request signature |
Content-Type: application/json | Content type must be JSON |
Signature Calculation
The signature is calculated using the SHA256 hash of the request body concatenated with your API secret.
bash
signature=$(echo -n "$requestBody$apiSecret" | sha256sum | cut -d' ' -f1)
Example in Different Languages
bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{"service":"energy","params":{"address":"TRX_ADDRESS","energy_amount":32000,"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({
service: 'energy',
params: {
address: 'TRX_ADDRESS',
energy_amount: 32000,
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([
'service' => 'energy',
'params' => [
'address' => 'TRX_ADDRESS',
'energy_amount' => 32000,
'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({
'service': 'energy',
'params': {
'address': 'TRX_ADDRESS',
'energy_amount': 32000,
'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())