Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
const client = createDfuseClient({ apiKey: DFUSE_API_KEY, network: DFUSE_API_NETWORK })
try {
// This example will work on EOS Mainnet only, change transaction id accordingly to test it out
const response = await client.fetchTransaction(
"1d5f57e9392d045ef4d1d19e6976803f06741e11089855b94efcdb42a1a41253"
)
console.log("Transaction lifecycle response", prettifyJson(response))
} catch (error) {
console.log("An error occurred", error)
}
client.release()
}
* might come in the future. This means that even if there is less
* results than expected per page, future blocks might add more
* results, hence the `cursor` not returning as empty.
*
* **Note** Doing a descending search will yield an empty
* string cursor at some point because you will reach the Genesis
* Block of the chain (Block #1).
*/
if (page.cursor === "" || page.transactions.length < resultPerPage) {
// No more pages, stop page fetch
break
}
console.log(`RAM Running Total (${resultCount} transactions included) is ${runningTotal}`)
console.log(`Fetching next page (#${pageCount + 1}) in 5s ...`)
await waitFor(5000)
}
console.log(`Running total is ${runningTotal}`)
console.log(`Completed after reading ${pageCount} page(s)`)
} catch (error) {
console.log("An error occurred", error)
}
client.release()
}
if (message.type === InboundMessageType.HEAD_INFO) {
console.log("WebSocket stream data.", JSON.stringify(message.data))
// Mark latest location where we want to start back at
wsStream.mark({ atBlockNum: message.data.head_block_num })
}
})
wsStream.onPostRestart = () => {
console.log()
console.log(
"<============= WebSocket stream has restarted to its previous `mark()` location =============>"
)
}
await waitFor(35000)
await graphqlStream.close()
await wsStream.close()
client.release()
}
const wsStream = await client.streamHeadInfo((message: InboundMessage) => {
if (message.type === InboundMessageType.ERROR) {
console.log("WebSocket stream error.", message.data)
return
}
if (message.type === InboundMessageType.LISTENING) {
console.log("WebSocket stream is now listening.")
}
if (message.type === InboundMessageType.HEAD_INFO) {
console.log("WebSocket stream data.", JSON.stringify(message.data))
// Mark latest location where we want to start back at
wsStream.mark({ atBlockNum: message.data.head_block_num })
}
})
(message: InboundMessage) => {
if (message.type === InboundMessageType.LISTENING) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ACTION_TRACE) {
/**
* JSON examples of various fields possibilities (since they might
* not always appear in the streaming time frame):
*
* ```
* {
* dbops: [
* // An `ActionTraceDbOp` row update operation
* {
* "op": "UPD",
* "action_idx": 8,
const wsStream = await client.streamHeadInfo((message: InboundMessage) => {
if (message.type === InboundMessageType.ERROR) {
console.log("WebSocket stream error.", message.data)
return
}
if (message.type === InboundMessageType.LISTENING) {
console.log("WebSocket stream is now listening.")
}
if (message.type === InboundMessageType.HEAD_INFO) {
console.log("WebSocket stream data.", JSON.stringify(message.data))
// Mark latest location where we want to start back at
wsStream.mark({ atBlockNum: message.data.head_block_num })
}
})
(message: InboundMessage) => {
if (message.type === InboundMessageType.LISTENING) {
console.log(prettifyJson(message.data))
return
}
if (message.type === InboundMessageType.ACTION_TRACE) {
/**
* JSON examples of various fields possibilities (since they might
* not always appear in the streaming time frame):
*
* ```
* {
* dbops: [
* // An `ActionTraceDbOp` row update operation
* {
* "op": "UPD",
* "action_idx": 8,
* "opayer": "eosbetbank11",
* "npayer": "eosbetbank11",
* "path": "eosio.token/eosbetbank11/accounts/........ehbo5",
* "old": "d11a231c0000000004454f5300000000",
* "new": "cd1a231c0000000004454f5300000000"
public async start() {
const dispatcher = dynamicMessageDispatcher({
listening: this.onListening,
action_trace: this.onAction,
progress: this.onProgress
})
console.log("Engine starting")
this.stream = await this.client.streamActionTraces(
{
accounts: "therealkarma",
action_names: "transfer"
},
dispatcher,
{
// You can use the `with_progress` to be sure to commit
// actions at least each 10 blocks. This is useful if your stream
// is low traffic so you don't need to wait until the next
public async start() {
console.log("Engine starting")
this.stream = await this.client.streamTableRows(
{
code: "eosio",
table: "global",
scope: "eosio"
},
dynamicMessageDispatcher({
listening: this.onListening,
table_delta: this.onTableDelta,
table_snapshot: this.onTableSnapshot,
progress: this.onProgress
}),
{
listen: true,
fetch: true,
// We use progress to display the current state of the table at a regular interval
with_progress: 50
}
)
}
const wsStream = await client.streamHeadInfo((message: InboundMessage) => {
if (message.type === InboundMessageType.ERROR) {
console.log("WebSocket stream error.", message.data)
return
}
if (message.type === InboundMessageType.LISTENING) {
console.log("WebSocket stream is now listening.")
}
if (message.type === InboundMessageType.HEAD_INFO) {
console.log("WebSocket stream data.", JSON.stringify(message.data))
// Mark latest location where we want to start back at
wsStream.mark({ atBlockNum: message.data.head_block_num })
}
})