Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface DfuseClient

The DfuseClient interface is the back-bone of the library. Based on the Facade pattern, this client is your single go to point for interacting with dfuse Stream API as well as the dfuse REST API.

The client contains only top-level methods enabling you to retrieve all the information you need for your next-gen blockchain project.

The dfuse Client takes care for you of:

  • Management of WebSocket connection (automatic connection/disconnection when needed).
  • Management of the API key (API token retrieval, freshness and persistence).
  • Abstract dfuse API into simple to use top-level methods.
  • Error handling wrapping error received via WebSocket and REST into easy to use error.
group

Interfaces

Hierarchy

  • DfuseClient

Implemented by

Index

Properties

Readonly endpoints

Returns the final resolved endpoints urls currenctly in used by the client to reach dfuse services.

This is useful when using Apollo Client passing it the computed url without effort.

 const wsLink = new WebSocketLink({
   uri: dfuseClient.endpoints.graphqlStreamUrl,
   ...,
 });

getTokenInfo

getTokenInfo: () => Promise<ApiTokenInfo>

Call this method each time you need an API token. Th returned API token is always valid. The expiration and the refresh of the token is handled automatically when using this method.

returns

A Promise that will resolve to a valid ApiTokenInfo instance, or will reject if an error occurs retrieving the API token.

Type declaration

Methods

apiRequest

  • An helper method that can be used to perform a generic HTTP call using the library inner configured HttpClient.

    This can be used to reach other REST API found on the nodeos process for example, those that are not directly included in the library but are still accessible via our endpoint like a /v1/chain/get_info or /v1/chain/push_transaction.

    Type parameters

    • T

    Parameters

    • path: string

      (required) The HTTP path on the endpoint

    • method: string

      (required) The HTTP method to perform the request agaisnt

    • Optional params: HttpQueryParameters

      (defaults {}) The HTTP query parameters to append to the url, they will be url-encoded and included in the final remote url. Has no effect when empty or undefined.

    • Optional body: any

      (defaults undefined) The HTTP body to include in the request, assumed to be a JSON object that will be serialized to a string. Not included in the HTTP request when undefined.

    • Optional headers: HttpHeaders

      (defaults {}) The extra HTTP headers to include in the request. Those will be merged with default ones ({ Authorization: ... }) and they override them if same key are specified.

    Returns Promise<T>

    A Promise that will resolve to the response body if it passes. Will reject with a DfuseApiError if it fits the dfuse Error Format or a generic DfuseError is it's something not fitting our expected format (nodeos erorr format for example).

authIssue

fetchBlockIdByTime

  • GET /v0/block_id/by_time

    Fetches the block ID, block time and block number for the given timestamp.

    Parameters

    • time: string | Date

      The reference timestamp to query for. If it's a string, assumed to be in ISO8601 extended format, i.e. 2019-03-04T10:36:14.5Z. If it's a date, it's going to be turned into an ISO8601 extended format relative to UTC.

    • comparator: ComparisonOperator

      Comparison operator for the block time. Should be one of:

      • gt (Greater Than time)
      • gte (Greater Than or Equal to time)
      • lt (Lower Than time)
      • lte (Lower Than or Equal totime)
      • eq (Strictly equal to time)

    Returns Promise<BlockIdByTimeResponse>

    A promise resolving to a BlockIdByTimeResponse object if the request was correct, or rejects with a DfuseApiError when it failed (or a more DfuseError when an unexpected error occurs).

fetchTransaction

graphql

  • Perform a query or mutation via the HTTP transport layer. The semantic of this method is to resolve the promise with the GraphQL response when the operation succeed on the server, whenever the actual GraphQL response contains an errors field or not.

    If an error at the HTTP error, the promise will be rejected.

    Type parameters

    • T = any

    Parameters

    • document: string | GraphqlDocument

      (required) The GraphQL operation document to perform. It must be either a query or mutation operation. A subscription operation is not supported by this method. You must use the method that accept options.onMessage to make it work.

    • Optional options: undefined | { operationType?: Exclude<GraphqlOperationType, "subscription">; variables?: GraphqlVariables }

      (optional) Specific options that can be provided

    Returns Promise<GraphqlResponse<T>>

  • Perform a query, mutation or subscription via the WebSocket transport layer. The semantic of this method is to resolve the promise with the Stream object if the connection was established correctly (or if it was already established) and the initial subscription message was sent correctly (this does not check if it was received correctly).

    Each message for the subscription will be sent to the onMessage handler defined on the options field.

    The Stream object can be used to control the stream. It can be marked via Stream.mark (so on reconnect, this stream restarts at the last marked location), joined via Stream.join (so you wait until the stream actually finishes) or closed via Stream.close.

    If we are unable to establish the connection or the initial send message cannot be sent, then the promise will reject with the appropriate error.

    Type parameters

    • T = any

    Parameters

    Returns Promise<Stream>

release

  • release(): void
  • Release any resources hold by this DfuseClient instance. Must be tolerant to being called multiple times.

    Once called, the instance is assumed unsuable and should never be invoked anymore.

    Returns void

searchTransactions

  • searchTransactions(q: string, options?: undefined | { blockCount?: undefined | number; cursor?: undefined | string; limit?: undefined | number; sort?: SearchSortType; startBlock?: undefined | number; withReversible?: undefined | false | true }): Promise<SearchTransactionsResponse>

stateAbi

  • stateAbi(account: string, options?: undefined | { blockNum?: undefined | number; json?: undefined | false | true }): Promise<StateAbiResponse>

stateAbiBinToJson

  • stateAbiBinToJson<T>(account: string, table: string, hexRows: string[], options?: undefined | { blockNum?: undefined | number }): Promise<StateAbiToJsonResponse<T>>
  • GET /v0/state/abi/bin_to_json

    Fetches the ABI for a given contract account, at any block height.

    see

    https://docs.dfuse.io/#rest-api-post-v0-state-abi-bin_to_json

    Type parameters

    • T = unknown

    Parameters

    • account: string

      Contract account targeted by the action.

    • table: string

      The name-encoded table name you want to retrieve. For example, user balances for tokens live in the accounts table. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • hexRows: string[]

      An array of hexadecimal rows to decode. Each row must be a valid hexadecimal string representation of the row to decode against the ABI.

    • Optional options: undefined | { blockNum?: undefined | number }

      (optional) Optional parameters

    Returns Promise<StateAbiToJsonResponse<T>>

stateKeyAccounts

  • stateKeyAccounts(publicKey: string, options?: undefined | { blockNum?: undefined | number }): Promise<StateKeyAccountsResponse>

statePermissionLinks

stateTable

  • stateTable<T>(account: string, scope: string, table: string, options?: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }): Promise<StateResponse<T>>
  • GET /v0/state/table

    Fetches the state of any table, at any block height.

    see

    https://docs.dfuse.io/#rest-api-get-v0-state-table

    Type parameters

    • T = unknown

    Parameters

    • account: string

      Contract account targeted by the action.

    • scope: string

      The name-encoded scope of the table you are requesting. For example, user balances for tokens live in their account name's scope. This is contract dependent, so inspect the ABI for the contract you are interested in.

    • table: string

      The name-encoded table name you want to retrieve. For example, user balances for tokens live in the accounts table. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • Optional options: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }

      (optional) Optional parameters

    Returns Promise<StateResponse<T>>

stateTableRow

  • stateTableRow<T>(account: string, scope: string, table: string, primaryKey: string, options?: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }): Promise<StateTableRowResponse<T>>
  • GET /v0/state/table/row

    Fetches a single row from the state of any table, at any block height.

    preview

    This endpoint is preview mode. This means it might be changed or removed and is not covered by breaking compatiblity policy of the project until it's out of preview.

    see

    https://docs.dfuse.io/#rest-api-get-v0-state-table-row

    Type parameters

    • T = unknown

    Parameters

    • account: string

      Contract account targeted by the action.

    • scope: string

      The name-encoded scope of the table you are requesting. For example, user balances for tokens live in their account name's scope. This is contract dependent, so inspect the ABI for the contract you are interested in.

    • table: string

      The name-encoded table name you want to retrieve. For example, user balances for tokens live in the accounts table. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • primaryKey: string

      The string representation of the primary key that you want to retrieve. The primaryKey is always a string, but can be encoded differently, for example name encoded like an account. The keyType is used to know how to transform the value in the string to the correct type.

    • Optional options: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }

      (optional) Optional parameters

    Returns Promise<StateTableRowResponse<T>>

stateTableScopes

  • stateTableScopes(account: string, table: string, options?: undefined | { blockNum?: undefined | number }): Promise<StateTableScopesResponse>
  • GET /v0/state/table_scopes

    Fetches a list of scopes, for a given table on a contract account, at any block height.

    see

    https://docs.dfuse.io/#rest-api-get-v0-state-table_scopes

    Parameters

    • account: string

      Contract account holding the requested table.

    • table: string

      The name-encoded table name you want to retrieve scopes from. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • Optional options: undefined | { blockNum?: undefined | number }

      (optional) Optional parameters

    Returns Promise<StateTableScopesResponse>

stateTablesForAccounts

  • stateTablesForAccounts<T>(accounts: string[], scope: string, table: string, options?: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }): Promise<MultiStateResponse<T>>
  • GET /v0/state/tables/accounts

    Fetches a table for a given contract account for a group of scopes, at any block height.

    see

    https://docs.dfuse.io/#rest-api-get-v0-state-tables-accounts

    Type parameters

    • T = unknown

    Parameters

    • accounts: string[]

      An AccountName list a maximum of 1500 elements can be present in the list.

    • scope: string

      A Name list, a maximum of 1500 elements can be present in the list.

    • table: string

      The name-encoded table name you want to retrieve. For example, user balances for tokens live in the accounts table. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • Optional options: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }

      (optional) Optional parameters

    Returns Promise<MultiStateResponse<T>>

stateTablesForScopes

  • stateTablesForScopes<T>(account: string, scopes: string[], table: string, options?: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }): Promise<MultiStateResponse<T>>
  • GET /v0/state/tables/scopes

    Fetches a table for a given contract account for a group of scopes, at any block height.

    see

    https://docs.dfuse.io/#rest-api-get-v0-state-tables-scopes

    Type parameters

    • T = unknown

    Parameters

    • account: string

      Contract account targeted by the action.

    • scopes: string[]
    • table: string

      The name-encoded table name you want to retrieve. For example, user balances for tokens live in the accounts table. Refer to the contract's ABI for a list of available tables. This is contract dependent.

    • Optional options: undefined | { blockNum?: undefined | number; json?: undefined | false | true; keyType?: StateKeyType; withAbi?: undefined | false | true; withBlockNum?: undefined | false | true }

      (optional) Optional parameters

    Returns Promise<MultiStateResponse<T>>

streamActionTraces

streamHeadInfo

streamTableRows

streamTransaction

Generated using TypeDoc