Calculate Energy Usage for Transfer
This endpoint estimates the energy required to transfer a specified amount from one address to another.
Endpoint
POST /transactions/estimate
Headers
Ensure the following headers are included in your request:
Content-Type: application/json
Accept: application/json
Authorization: Bearer {TOKEN}
X-Txc-Signature: {SIGN}
Request Body
Field | Type | Description |
---|---|---|
from | string | Sender's address. |
to | string | Recipient's address. |
amount | string | Amount to transfer (in USDT). |
Example Request Body
json
{
"from": "address1",
"to": "address2",
"amount": "5"
}
Example Request
PHP
php
// Replace these with your actual data
$url = "https://dev-site.evelar.energy/api/v1/transactions/estimate";
$token = "YOUR_TOKEN";
$secret = "MYSECRET";
$body = json_encode([
"from" => "address1",
"to" => "address2",
"amount" => "5"
]);
// Generate the signature
$sign = hash('sha256', $body . $secret);
// Headers
$headers = [
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Bearer $token",
"X-Txc-Signature: $sign"
];
// Initialize cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute request and get the response
$response = curl_exec($ch);
curl_close($ch);
// Output response
echo $response;
Python
python
import requests
import hashlib
import json
url = "https://dev-site.evelar.energy/api/v1/transactions/estimate"
token = "YOUR_TOKEN"
secret = "MYSECRET"
body = json.dumps({
"from": "address1",
"to": "address2",
"amount": "5"
})
# Generate the signature
sign = hashlib.sha256((body + secret).encode('utf-8')).hexdigest()
# Headers
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {token}",
"X-Txc-Signature": sign
}
# Make the request
response = requests.post(url, headers=headers, data=body)
print(response.json())
Node.js
javascript
const axios = require('axios');
const crypto = require('crypto');
const url = "https://dev-site.evelar.energy/api/v1/transactions/estimate";
const token = "YOUR_TOKEN";
const secret = "MYSECRET";
const body = JSON.stringify({
from: "address1",
to: "address2",
amount: "5"
});
// Generate the signature
const sign = crypto.createHash('sha256').update(body + secret).digest('hex');
// Headers
const headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": `Bearer ${token}`,
"X-Txc-Signature": sign
};
// Make the request
axios.post(url, body, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
Bash
bash
url="https://dev-site.evelar.energy/api/v1/transactions/estimate"
token="YOUR_TOKEN"
secret="MYSECRET"
body='{"from":"address1","to":"address2","amount":"5"}'
# Generate the signature
sign=$(echo -n "$body$secret" | openssl dgst -sha256 -hex | awk '{print $2}')
# Make the request
curl -X POST $url \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $token" \
-H "X-Txc-Signature: $sign" \
-d "$body"
Example Response
json
{
"code": 0,
"result": {
"energy_usage": 1906, // Amount of energy needed
"activated": true // Indicates if the address needs activation
}
}
Response Fields
Field | Type | Description |
---|---|---|
code | int | Response status code. |
energy_usage | int | Estimated energy required for the transfer. |
activated | boolean | Indicates whether the address needs activation. |