API Key

什么是API Key

TronGrid不但提供TRON全节点所提供的所有HTTP API,它还提供其特有的扩展 API,为了保证请求资源的合理分配,所有对TronGrid的请求都需要带参数API Key,没有API Key的请求将被严格限速,甚至不响应。

📘

通过Trongrid访问TRON主网时,需要设置API Key,访问Shasta / Nile测试网时,不需要设置API Key。

如何获取API Key

用户登录 Trongrid 后,在Dashboard页面或API Key列表页面可快速创建API Key,每个API Key都有单独的配置页面,用户可配置不同的API Key满足不同的需求。

如何使用API Key

在访问TronGrid的请求的Header中添加参数 TRON_PRO_API_KEY=API Key

示例:

curl -X POST \
  https://api.trongrid.io/wallet/createtransaction \
  -H 'Content-Type: application/json' \
  -H 'TRON_PRO_API_KEY: 25f66928-0b70-48cd-9ac6-da6f8247c663' \
  -d '{
    "to_address": "41e9d79cc47518930bc322d9bf7cddd260a0260a8d",
    "owner_address": "41D1E7A6BC354106CB410E65FF8B181C600FF14292",
    "amount": 1000
}'
import requests

url = "https://api.trongrid.io/wallet/createtransaction"

payload = "{\n    \"to_address\": \"41e9d79cc47518930bc322d9bf7cddd260a0260a8d\",\n    \"owner_address\": \"41D1E7A6BC354106CB410E65FF8B181C600FF14292\",\n    \"amount\": 1000\n}"
headers = {
    'Content-Type': "application/json",
    'TRON_PRO_API_KEY': "25f66928-0b70-48cd-9ac6-da6f8247c663"
    }
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.trongrid.io/wallet/createtransaction',
  headers: {  
     'TRON_PRO_API_KEY ': '25f66928-0b70-48cd-9ac6-da6f8247c663',
     'Content-Type': 'application/json' 
},
  body: { 
      to_address: '41e9d79cc47518930bc322d9bf7cddd260a0260a8d',
     owner_address: '41D1E7A6BC354106CB410E65FF8B181C600FF14292',
     amount: 1000 
},
  json: true 
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});