Bandwidth automático
Añadir contrato de token
Añade un token TRC-20 propio para Bandwidth automático
POST
/
v1
/
bandwidth
/
auto
/
contracts
Añadir contrato de token
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_bodyAñadir contrato de token
Añade un contrato TRC-20 a tu lista de tokens, para que una suscripción pueda usarlo contoken: "CUSTOM" u "OWN". Consultamos a la red si la dirección es un token TRC-20 cuyas transferencias se ejecutan, y leemos su símbolo, nombre, decimales y cuánto ancho de banda consume una transferencia. Requiere el alcance buy_bandwidth.
Añadir un contrato que ya está en tu lista lo devuelve de nuevo, sin una nueva comprobación y sin contar para el límite de solicitudes.
Cuerpo de la solicitud
Dirección del contrato TRC-20 (formato T…, 34 caracteres). USDT y USDD se rechazan — elígelos con
token.Respuesta
El contrato, con los mismos campos que en Listar contratos de token. Usabandwidth como guía para el volume de la suscripción, con un pequeño margen.
Ejemplo
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
}
Errores
| Estado | Código | Cuándo |
|---|---|---|
400 | INVALID_ADDRESS | address no es una dirección TRON válida |
400 | AUTO_BW_NOT_A_CONTRACT | No hay ningún contrato inteligente en esta dirección |
400 | AUTO_BW_NOT_A_TOKEN | El contrato no es un token TRC-20 |
400 | AUTO_BW_TRANSFER_REVERTS | Una transferencia de este token falla en la simulación — por ejemplo, el token está en pausa |
403 | FORBIDDEN | La clave API carece del alcance buy_bandwidth |
409 | AUTO_BW_CONTRACT_LISTED | Es USDT o USDD — elígelo con token; el token figura en error.token |
409 | AUTO_BW_CONTRACT_LIMIT | Tu lista ya tiene 20 contratos — quita uno primero |
429 | RATE_LIMIT_EXCEEDED | Demasiados contratos nuevos — ver Límites de tasa |
503 | AUTO_BW_DISABLED | Bandwidth automático está desactivado temporalmente — reintenta más tarde |
503 | TEMPORARILY_UNAVAILABLE | No se pudo leer la red en este momento; no se guardó nada — reintenta pasados los segundos de Retry-After |
{
"detail": {
"error": {
"code": "AUTO_BW_CONTRACT_LISTED",
"message": "This is USDT; pick it in the token list",
"token": "USDT"
}
}
}
⌘I
Añadir contrato de token
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