Авто-bandwidth
Добавить контракт токена
Добавить собственный токен TRC-20 для Авто-bandwidth
POST
/
v1
/
bandwidth
/
auto
/
contracts
Добавить контракт токена
curl --request POST \
--url https://api.tronrental.com/v1/bandwidth/auto/contracts \
--header 'Content-Type: application/json' \
--data '
{
"address": "<string>"
}
'import requests
url = "https://api.tronrental.com/v1/bandwidth/auto/contracts"
payload = { "address": "<string>" }
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({address: '<string>'})
};
fetch('https://api.tronrental.com/v1/bandwidth/auto/contracts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tronrental.com/v1/bandwidth/auto/contracts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'address' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tronrental.com/v1/bandwidth/auto/contracts"
payload := strings.NewReader("{\n \"address\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.tronrental.com/v1/bandwidth/auto/contracts")
.header("Content-Type", "application/json")
.body("{\n \"address\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tronrental.com/v1/bandwidth/auto/contracts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"address\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyДобавить контракт токена
Добавляет контракт TRC-20 в ваш список токенов, чтобы подписка могла использовать его сtoken: "CUSTOM" или "OWN". Мы спрашиваем у сети, является ли адрес токеном TRC-20, переводы которого проходят, и считываем его символ, название, число знаков и то, сколько bandwidth занимает один перевод. Нужен скоуп buy_bandwidth.
Добавление контракта, который уже есть в вашем списке, возвращает его снова — без новой проверки и без учёта в лимите запросов.
Тело запроса
Адрес контракта TRC-20 (формат T…, 34 символа). USDT и USDD отклоняются — выбирайте их через
token.Ответ
Контракт — с теми же полями, что в Списке контрактов токенов. Используйтеbandwidth как ориентир для volume подписки, с небольшим запасом.
Пример
curl -X POST https://api.tronrental.com/v1/bandwidth/auto/contracts \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{"address": "TYourTokenContract1234567890abcdef"}'
import requests
resp = requests.post(
"https://api.tronrental.com/v1/bandwidth/auto/contracts",
headers={"X-API-Key": "your_api_key"},
json={"address": "TYourTokenContract1234567890abcdef"},
)
print(resp.json())
const resp = await fetch("https://api.tronrental.com/v1/bandwidth/auto/contracts", {
method: "POST",
headers: { "X-API-Key": "your_api_key", "Content-Type": "application/json" },
body: JSON.stringify({ address: "TYourTokenContract1234567890abcdef" }),
});
console.log(await resp.json());
Response
{
"address": "TYourTokenContract1234567890abcdef",
"symbol": "MTK",
"name": "My Token",
"decimals": 6,
"bandwidth": 345
}
Ошибки
| Статус | Код | Когда |
|---|---|---|
400 | INVALID_ADDRESS | address — некорректный адрес TRON |
400 | AUTO_BW_NOT_A_CONTRACT | По этому адресу нет смарт-контракта |
400 | AUTO_BW_NOT_A_TOKEN | Контракт не является токеном TRC-20 |
400 | AUTO_BW_TRANSFER_REVERTS | Перевод этого токена не проходит в симуляции — например, токен приостановлен |
403 | FORBIDDEN | У API-ключа нет скоупа buy_bandwidth |
409 | AUTO_BW_CONTRACT_LISTED | Это USDT или USDD — выбирайте его через token; токен указан в error.token |
409 | AUTO_BW_CONTRACT_LIMIT | В вашем списке уже 20 контрактов — сначала удалите один |
429 | RATE_LIMIT_EXCEEDED | Слишком много новых контрактов — см. Лимиты запросов |
503 | AUTO_BW_DISABLED | Авто-bandwidth временно выключен — повторите позже |
503 | TEMPORARILY_UNAVAILABLE | Сеть сейчас не удалось прочитать; ничего не сохранено — повторите через число секунд из Retry-After |
{
"detail": {
"error": {
"code": "AUTO_BW_CONTRACT_LISTED",
"message": "This is USDT; pick it in the token list",
"token": "USDT"
}
}
}
⌘I
Добавить контракт токена
curl --request POST \
--url https://api.tronrental.com/v1/bandwidth/auto/contracts \
--header 'Content-Type: application/json' \
--data '
{
"address": "<string>"
}
'import requests
url = "https://api.tronrental.com/v1/bandwidth/auto/contracts"
payload = { "address": "<string>" }
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({address: '<string>'})
};
fetch('https://api.tronrental.com/v1/bandwidth/auto/contracts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tronrental.com/v1/bandwidth/auto/contracts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'address' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tronrental.com/v1/bandwidth/auto/contracts"
payload := strings.NewReader("{\n \"address\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.tronrental.com/v1/bandwidth/auto/contracts")
.header("Content-Type", "application/json")
.body("{\n \"address\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tronrental.com/v1/bandwidth/auto/contracts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"address\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body