自动带宽
添加代币合约
为自动带宽添加您自己的 TRC-20 代币
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 代币,并读取其符号、名称、小数位数以及一笔转账所需的带宽。需要 buy_bandwidth 权限。
添加已在您列表中的合约会再次返回该合约,不会重新检查,也不计入请求限制。
请求体
响应
该合约,字段与列出代币合约中的相同。请以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 | 自动带宽暂时关闭——请稍后重试 |
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