简介:BlockDog 方块狗是公鹿钱包团队推出的网站。他们借用这个网站提供公共 API 服务以方便 EOS 开发者进行 EOS 相关开发。本文整理使用 BlockDog API 进行 EOS 官方 RPC 接口查询。
BlockDog 方块狗是公鹿钱包团队推出的网站。他们借用这个网站提供公共 API 服务以方便 EOS 开发者进行 EOS 相关开发。
本文整理使用 BlockDog API 进行 EOS 官方 RPC 接口查询。
BlockDog API 官方文档:https://open-api.eos.blockdog.com/
使用 BlockDog API 需要申请 apikey
://www.blockdog.com/openApi
免费版 apikey
支持 HTTPS API 调用频次≤3次/秒,WebSocket API 订阅合约/账户调用峰值≤3次。
BlockDog API 服务思维导图:
BlockDog API.png通过思维导图可以看到 BlockDog API 支持哪些 EOS 官方 RPC 接口。
这里以 get_info(获取 EOS 区块链基本信息)和 get_account(获取账户基本信息)为例示例使用 BlockDog API 进行 EOS 官方 RPC 接口查询:
get_info:
Node.js 示例:
let request = require("request");
let options = { method: 'POST',
url: 'https://open-api.eos.blockdog.com/v1/chain/get_info',
headers:
{ apikey: '5b4added-e80c-41fb-b5a9-16269d2de79b',
accept: '*/*' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回的 JSON 示例:
{
"server_version": "ced8d7db",
"chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
"head_block_num": 53930061,
"last_irreversible_block_num": 53929729,
"last_irreversible_block_id": "0336e701eaab996a025ba78b3577cb0053717ad1bd917fcc03c79d3519836eba",
"head_block_id": "0336e84d13448aa595e19bc481e394c0a6b010196068caf26136b4500e40c5bf",
"head_block_time": "2019-04-20T08:53:27.500",
"head_block_producer": "argentinaeos",
"virtual_block_cpu_limit": 200000000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 199541,
"block_net_limit": 1048384,
"server_version_string": "v1.5.3-dirty"
}
get_account:
Node.js 示例:
var request = require("request");
var options = { method: 'POST',
url: 'https://open-api.eos.blockdog.com/v1/chain/get_account',
headers:
{ 'content-type': 'application/json',
apikey: '5b4added-e80c-41fb-b5a9-16269d2de79b',
accept: '*/*' },
body: '{"account_name":"eosio"}' };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
返回的 JSON 示例:
{
"account_name": "eosio",
"head_block_num": 53939638,
"head_block_time": "2019-04-20T10:13:18.000",
"privileged": true,
"last_code_update": "2019-01-09T08:22:24.000",
"created": "2018-06-08T08:08:08.500",
"core_liquid_balance": "1901.7246 EOS",
"ram_quota": 36333367,
"net_weight": -1,
"cpu_weight": -1,
"net_limit": {
"used": -1,
"available": -1,
"max": -1
},
"cpu_limit": {
"used": -1,
"available": -1,
"max": -1
},
"ram_usage": 33326461,
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [],
"accounts": [{
"permission": {
"actor": "eosio.prods",
"permission": "active"
},
"weight": 1
}],
"waits": []
}
}, {
"perm_name": "owner",
"parent": "",
"required_auth": {
"threshold": 1,
"keys": [],
"accounts": [{
"permission": {
"actor": "eosio.prods",
"permission": "active"
},
"weight": 1
}],
"waits": []
}
}],
"total_resources": {
"owner": "eosio",
"net_weight": "0.0000 EOS",
"cpu_weight": "0.1200 EOS",
"ram_bytes": 0
},
"self_delegated_bandwidth": null,
"refund_request": null,
"voter_info": {
"owner": "eosio",
"proxy": "",
"producers": [],
"staked": 0,
"last_vote_weight": "0.00000000000000000",
"proxied_vote_weight": "0.00000000000000000",
"is_proxy": 0,
"flags1": 7,
"reserved2": 0,
"reserved3": "0 "
}
}
除此之外,BlockDog API 还在 Github 提供了官方的 API Python 使用示例:https://github.com/blockdogcom/open-api-demo
里面有诸如 get_info 的 python 使用示例:
from eos.cleos import MyCleos
APIKEY = '5b4added-e80c-41fb-b5a9-16269d2de79b'
ENDPOINT = 'https://open-api.eos.blockdog.com'
ce = MyCleos(ENDPOINT, APIKEY)
# 获取区块信息
result = ce.get_info()
print('链ID', result['chain_id'])
print('最新区块高度', result['head_block_num'])
print('最新区块时间', result['head_block_time'])
print('最新不可逆区块高度', result['last_irreversible_block_num'])
我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:
区块链社群 知识星球
网友评论