dfuse-eosio 常用GraphQL API接口整理
测试例子
https://github.com/dfuse-io/docs/tree/master/quickstarts
@ dfuse/client使用例子
global.fetch = require('node-fetch');
global.WebSocket = require('ws');
// CODE:BEGIN:quickstarts_javascript_node_eos_section1
const { createDfuseClient } = require('@dfuse/client');
const client = createDfuseClient({
network: '39.106.103.152:8080',
authentication: false,
secure: false,
});
// CODE:END:quickstarts_javascript_node_eos_section1
// CODE:BEGIN:quickstarts_javascript_node_eos_section2
// You must use a `$cursor` variable so stream starts back at last marked cursor on reconnect!
const operation = `subscription($cursor: String!) {
searchTransactionsForward(query:"receiver:eosio.token action:transfer -data.quantity:'0.0001 EOS'", cursor: $cursor) {
undo cursor
trace { id matchingActions { json } }
}
}`;
// CODE:END:quickstarts_javascript_node_eos_section2
// CODE:BEGIN:quickstarts_javascript_node_eos_section3
async function main() {
const stream = await client.graphql(operation, message => {
if (message.type === 'data') {
const {
undo,
cursor,
trace: { id, matchingActions }
} = message.data.searchTransactionsForward;
matchingActions.forEach(({ json: { from, to, quantity } }) => {
console.log(
`Transfer ${from} -> ${to} [${quantity}]${undo ? ' REVERTED' : ''}`
);
});
// Mark stream at cursor location, on re-connect, we will start back at cursor
stream.mark({ cursor });
}
if (message.type === 'error') {
console.log('An error occurred', message.errors, message.terminal);
}
if (message.type === 'complete') {
console.log('Completed');
}
});
// Waits until the stream completes, or forever
await stream.join();
await client.release();
}
// CODE:END:quickstarts_javascript_node_eos_section3
// CODE:BEGIN:quickstarts_javascript_node_eos_section4
main().catch(error => console.log('Unexpected error', error));
// CODE:END:quickstarts_javascript_node_eos_section4
接口文档
https://docs.dfuse.io/eosio/public-apis/reference/graphql-api/
常用接口整理
稍后补充
GraphQL 与 REST 相比的优势和短板
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »