RPC 服务
功能简介
主要提供节点附带的原生 RPC 接口功能
接口地址
POST https://dt-api.upyun.com/v1/rpc/btc/{token}/
POST https://dt-api.upyun.com/v1/rpc/eth/{token}/
GET POST https://dt-api.upyun.com/v1/rpc/eos/{token}/
GET POST https://dt-api.upyun.com/v1/rpc/tron/{token}/
GET POST https://dt-api.upyun.com/v1/rpc/grin/{token}/
CURL 请求示例
curl -X POST \
https://dt-api.upyun.com/v1/rpc/btc/42827_40_4_5204d7fe2c04403a8dcf4e0754ffc742/ \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"jsonrpc": "1.0",
"id": "1",
"method": "getblock",
"params": [
"000000000b677ee3c6397f21f28735891462d0d649939e7afc029f59349f546d", 2
]
}'
curl -X POST \
https://dt-api.upyun.com/v1/rpc/eth/42827_40_4_5204d7fe2c04403a8dcf4e0754ffc742/ \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [
],
"id": 2
}'
curl -X POST \
https://dt-api.upyun.com/v1/rpc/eos/42827_40_4_5204d7fe2c04403a8dcf4e0754ffc742/v1/chain/get_info \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
curl -X POST \
https://dt-api.upyun.com/v1/rpc/tron/42827_40_4_5204d7fe2c04403a8dcf4e0754ffc742/wallet/getnowblock \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
curl -X GET \
https://dt-api.upyun.com/v1/rpc/grin/42827_40_4_5204d7fe2c04403a8dcf4e0754ffc742/v1/headers/1 \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
PLUS 服务
功能简介
主要提供节点原生接口不具备的功能
接口地址
POST https://dt-api.upyun.com/v1/plus/tron/{token}/
文档地址
WebSokcet 服务
功能简介
主要提供订阅服务,减少客户端需要频繁轮训和遍历的问题
接口地址
wss://dt-api.upyun.com/v1/ws/btc/{token}/
wss://dt-api.upyun.com/v1/ws/eth/{token}/
wss://dt-api.upyun.com/v1/ws/eos/{token}/
wss://dt-api.upyun.com/v1/ws/tron/{token}/
wss://dt-api.upyun.com/v1/ws/grin/{token}/
文档地址 支持类型 subscribe
unsubscribe
支持方法 get_blocks
更多方法支持 敬请期待
nodejs 示例
const WebSocket = require('ws')
const host = 'wss://dt-api.upyun.com'
const token = '42827_40_15_795e06bec6344648b67139f008e633ae'
function generateWsClient (coinType) {
const ws = new WebSocket(`${host}/v1/ws/${coinType}/${token}/`, {
perMessageDeflate: true
})
ws.on('open', function open () {
ws.send(JSON.stringify({
action: 'subscribe',
method: 'get_account_related_txs',
params: {
account: 'eosio.token'
}
}))
ws.send(JSON.stringify({
action: 'subscribe',
method: 'get_blocks',
params: {
}
}))
setTimeout(() => {
ws.send(JSON.stringify({
action: 'unsubscribe',
method: 'get_blocks',
params: {}
}))
ws.send(JSON.stringify({
action: 'unsubscribe',
method: 'get_account_related_txs',
params: {}
}))
}, 10000)
})
ws.on('close', function close () {
console.log('disconnected')
})
ws.on('message', function incoming (data) {
data = JSON.parse(data)
console.log(JSON.stringify(data, null, 2))
})
}
const coins = ['eos']
for (const coinType of coins) {
generateWsClient(coinType)
}