How to use the @dfuse/client.createDfuseClient function in @dfuse/client

To help you get started, we’ve selected a few @dfuse/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfuse-io / client-js / examples / reference / fetch-transaction.ts View on Github external
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()
}
github dfuse-io / client-js / examples / basic / graphql-search-your-latest-transactions.ts View on Github external
async function main() {
  const client = createDfuseClient({ apiKey: DFUSE_API_KEY, network: DFUSE_API_NETWORK })

  const searchTransactions = `query ($limit: Int64!) {
    searchTransactionsBackward(query: "auth:${account}", limit: $limit) {
      results {
        block { num }
        trace { id matchingActions { json } }
      }
    }
  }`

  try {
    const response = await client.graphql(searchTransactions, {
      variables: { limit: 10 }
    })

    console.log()
github dfuse-io / client-js / examples / advanced / client-and-socket-notifications.ts View on Github external
console.log("Socket emitted an error event.", {
        message: event.message,
        error: event.error
      })
    },

    onClose(event: any) {
      console.log("Socket has closed its connection.", { reason: event.reason, code: event.code })
    },

    onReconnect() {
      console.log("Socket has been reconnected with remote server.")
    }
  }

  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK,
    streamClientOptions: {
      socketOptions
    },
    graphqlStreamClientOptions: {
      socketOptions
    }
  })

  const graphqlOperation = `subscription($cursor: String!) {
    searchTransactionsForward(query: "action:onblock", cursor: $cursor) {
      undo cursor
      block { num timestamp }
    }
  }`
github dfuse-io / client-js / examples / reference / stream-head-info.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK
  })

  const stream = await client.streamHeadInfo((message: InboundMessage) => {
    if (message.type === InboundMessageType.LISTENING) {
      console.log(prettifyJson(message.data))
      return
    }

    if (message.type === InboundMessageType.HEAD_INFO) {
      console.log(prettifyJson(message.data))
      return
    }
  })
github dfuse-io / client-js / examples / advanced / graphql-gql-tag.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK
  })

  try {
    const response = (await client.graphql(printGraphqlDocument(searchTransferQuery), {
      variables: { limit: 10 }
    })) as GraphqlResponse

    console.log(prettifyJson(response))
  } catch (error) {
    console.log("An error occurred", error)
  }

  client.release()
}
github dfuse-io / client-js / examples / advanced / track-ram-usage.ts View on Github external
async function main() {
  const client = createDfuseClient({ apiKey: DFUSE_API_KEY, network: DFUSE_API_NETWORK })
  const query = `(ram.released:${account} OR ram.consumed:${account})`

  try {
    let resultCount = 0
    let runningTotal = 0
    let cursor = ""
    let pageCount = 0

    while (resultCount <= maxResults) {
      const page = await fetchPage(client, query, cursor)
      pageCount++

      resultCount += page.transactions.length
      cursor = page.cursor

      page.transactions.forEach((result: SearchTransactionRow) => {
github dfuse-io / client-js / examples / advanced / never-miss-a-beat.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK,
    streamClientOptions: {
      socketOptions: {
        reconnectDelayInMs: 250
      }
    }
  })

  const engine = new Engine(client)
  await engine.start()

  await waitFor(50000)
  await engine.stop()

  client.release()
github dfuse-io / client-js / examples / advanced / graphql-never-miss-a-beat.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: DFUSE_API_KEY,
    network: DFUSE_API_NETWORK,
    graphqlStreamClientOptions: {
      socketOptions: {
        reconnectDelayInMs: 250
      }
    }
  })

  const engine = new Engine(client)
  await engine.run()

  client.release()
}
github dfuse-io / client-js / examples / advanced / nodejs-fetch-and-websocket-options.ts View on Github external
async function main() {
  const client = createDfuseClient({
    apiKey: process.env.DFUSE_API_KEY!,
    network: process.env.DFUSE_API_NETWORK || "mainnet",
    httpClientOptions: {
      fetch: nodeFetch
    },
    graphqlStreamClientOptions: {
      socketOptions: {
        webSocketFactory
      }
    },
    streamClientOptions: {
      socketOptions: {
        webSocketFactory
      }
    }
  })
github dfuse-io / dfuse-eosio / eosq / src / data / dfuse.ts View on Github external
export const initializeDfuseClientFromConfig = () => {
  initializeDfuseClient(
    createDfuseClient({
      apiKey: Config.dfuse_io_api_key,
      network: Config.dfuse_io_endpoint,
      authUrl: Config.dfuse_auth_endpoint,
      secure: Config.secure !== undefined && Config.secure
    })
  )
}