Document
With this system, you can rent energy on the TRON network.
Getting Started
First, you will need api_key and secret_key. These API keys located in your account. You are required it when
you want to use API key for interact with service.
Also you required to restrict API access to your own secure IP addresses. If you do not know your server's
IPaddress, you can run this command on your server.
curl 'https://energy.wallet.ir/api/'
API Key Setup
First, get API key and secret key from panel and choose method's that you need.
Never share your API key/secret key to ANYONE.
API key and secret key will be something like this:
API Key: 4f3c12fa0a1d1ac8b026298b980f16b2 SECRET KEY: f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6For each request you must send two params in header, one of this is
api_key
and another is api_sign
you must create api_sign by hmac_hash sha256 on params that you will be sent!
for example: you want to send
par1=value1
and par2=value2
to API at the first you must create
api_sign
string by secret_key
.
PHP:
$post_encode = http_build_query([ 'par1'=>'value1', 'par2'=>'value2' ]); $s = hash_hmac('sha256', $post_encode, 'f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6', true); echo base64_encode($s); //g1seBV5gkv7n4EjIdzMjl+ntJ256kvIe2kulu2SfTPk=
Node.js:
var crypto = require('crypto'); var hash = crypto.createHmac('SHA256', "f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6").update("par1=value1&par2=value2").digest('base64');
Python:
import hashlib import hmac import base64 dataToBeSigned= bytes("par1=value1&par2=value2").encode('utf-8') portalKey = bytes("f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6").encode('utf-8') signature = base64.b64encode(hmac.new(portalKey, dataToBeSigned, digestmod=hashlib.sha256).digest())
Ruby:
require 'openssl' require "base64" hash = OpenSSL::HMAC.digest('sha256', "f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6", "par1=value1&par2=value2") token = Base64.encode64(hash) token.delete("\n")
Java:
import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class ApiSecurityExample { public static void main(String[] args) { String portalKey = "f7d36fd7f60ab0bac12051e0c3240508585dba741e126669bfbc06e002b9df6ac4e457b6"; String dataToBeSigned= "par1=value1&par2=value2"; Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(portalKey.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key); String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(dataToBeSigned.getBytes())); } }
Send request
At this level , you must have api_key
and api_sign
and params that you want to send
par1=value1&par2=value2
send params via post method to API and set api_key
and api_sign
in header .
CURL
curl -H "api_key:4f3c12fa0a1d1ac8b026298b980f16b2" -H "api_sign:g1seBV5gkv7n4EjIdzMjl+ntJ256kvIe2kulu2SfTPk=" --data "par1=value1&par2=value2" https://energy.wallet.ir/api/example
PHP
$_headers = [ 'api_key:4f3c12fa0a1d1ac8b026298b980f16b2', 'api_sign:g1seBV5gkv7n4EjIdzMjl+ntJ256kvIe2kulu2SfTPk=', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); curl_setopt($ch, CURLOPT_URL, 'https://energy.wallet.ir/api/example'); curl_setopt($ch, CURLOPT_POSTFIELDS, 'par1=value1&par2=value2'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($ch); curl_close($ch); echo $result;
Response
All response is json format .
Success Sample:
{ ... "success": true, "status": 200 }success will be true if everything is fine and status is same as a http status code.
Failed Sample:
{ "errors": { "auth": "INVALID_API_SIGN" }, "success": false, "status": 403 }
Period List
POST https://energy.wallet.ir/api/periodlist
Name | Type | Mandatory | Description |
amount | integer | no | The amount of energy you want to rent. default is 32000 |
Response:
{ "amount": 32000, "costList": { "7200": "2 hours » 2.8 TRX", "21600": "6 hours » 3.2 TRX", "43200": "12 hours » 4 TRX", "86400": "one day » 6 TRX", "604800": "one week » 36 TRX", "2592000": "one month » 144 TRX", "5184000": "2 months » 270 TRX" }, "rateList": { "7200": "0.0000875", "21600": "0.0001", "43200": "0.000125", "86400": "0.0001875", "604800": "0.001125", "2592000": "0.0045", "5184000": "0.0084375" }, "success": true, "status": 200 }
Resource
POST https://energy.wallet.ir/api/resource
address | string | yes | Tron Address |
Response:
{ "energy": 5497487, "bandwidth": 10856, "total_bandwidth": 11456, "success": true, "status": 200 }
Rent Energy
POST https://energy.wallet.ir/api/rent-energy
Name | Type | Mandatory | Description |
amount | integer | yes | The amount of energy you want to rent |
address | integer | yes | Address |
period | integer | yes | Period by seconds |
Response:
{ "result": "66-1-7912d4f025", "item": { "id": 66, "trackid": "66-1-7912d4f025", "address": "TMptovyxwE8N8GaVFzu4yS5jeinH27oSgd", "resource": "ENERGY", "amount": "15000.0000000000", "period": 7200, "price": "0.0000875000", "cost": "1.3125000000", "date": "2023-09-11", "time": 1694498554, "assign_time": 0, "txid": null, "status": "waiting" }, "success": true, "status": 200 }
RentList
POST https://energy.wallet.ir/api/rent-list
Name | Type | Mandatory | Description |
trackid | string | no | |
amount | integer | no | |
period | integer | no | |
txid | string | no | |
status | string | no | waiting , success , failed |
resource | string | no | ENERGY , BANDWIDTH |
address | string | no | |
page | integer | yes | |
limit | integer | yes | min 1 , max 100 |
Response:
{ "items": [ { "id": 66, "trackid": "66-1-7912d4f025", "address": "TMptovyxwE8N8GaVFzu4yS5jeinH27oSgd", "resource": "ENERGY", "amount": "15000.0000000000", "period": 7200, "price": "0.0000875000", "cost": "1.3125000000", "date": "2023-09-11", "time": 1694498554, "assign_time": 0, "txid": null, "status": "waiting" }, { "id": 65, "trackid": "65-1-99c9bb46af", "address": "TMptovyxwE8N8GaVFzu4yS5jeinH27oSgd", "resource": "ENERGY", "amount": "15000.0000000000", "period": 7200, "price": "0.0000875000", "cost": "1.3125000000", "date": "2023-09-11", "time": 1694498483, "assign_time": 0, "txid": '2aca9f3f7e0944058b86ec720a7bf9540f77a3e920a08c6e5d713f16d61d800f', "status": "success" }, { "id": 64, "trackid": "64-1-fc5433ba0b", "address": "TMptovyxwE8N8GaVFzu4yS5jeinH27oSgd", "resource": "ENERGY", "amount": "15000.0000000000", "period": 7200, "price": "0.0000875000", "cost": "1.3125000000", "date": "2023-09-11", "time": 1694498307, "assign_time": 0, "txid": null, "status": "failed" } ], "total": 3, "limit": 10, "page": 1, "success": true, "status": 200 }
Balance
POST https://energy.wallet.ir/api/balance
Response:
{ "balance_list": [ { "balance": "3.9375", "currency": "TRX" } ], "deposit_address": "TBCh4JKZqCDZ9aXJti6uAwQTusWJCoeZv2", "success": true, "status": 200 }
Balance List
POST https://energy.wallet.ir/api/balance-list
Name | Type | Mandatory | Description |
trackid | string | no | |
add | float | no | |
take | float | no | |
type | string | no | RentEnergy, deposit, AddConvert, TakeConvert, ActiveAddress |
page | integer | yes | |
limit | integer | yes | min 1 , max 100 |
Response:
{ "items": [ { "add": "0.00000000000000000000", "take": "1.31250000000000000000", "balance": "-3.93750000000000000000", "trackid": "66-1-7912d4f025", "type": "RentEnergy", "time": 1694498554, "date": "2023-09-12T06:02:34+00:00", "coin": "TRX" }, { "add": "0.00000000000000000000", "take": "1.31250000000000000000", "balance": "-2.62500000000000000000", "trackid": "65-1-99c9bb46af", "type": "RentEnergy", "time": 1694498483, "date": "2023-09-12T06:01:23+00:00", "coin": "TRX" }, { "add": "0.00000000000000000000", "take": "1.31250000000000000000", "balance": "-1.31250000000000000000", "trackid": "64-1-fc5433ba0b", "type": "RentEnergy", "time": 1694498307, "date": "2023-09-12T05:58:27+00:00", "coin": "TRX" } ], "total": 3, "limit": 10, "page": 1, "success": true, "status": 200 }