### Install and Run All ERC20 Example Source: https://github.com/enviodev/hypersync-client-node/blob/main/examples/all-erc20/README.md This bash script outlines the steps to clone the hypersync-client-node repository, navigate to the all-erc20 example directory, install dependencies, build the project, and start the example script. ```bash git clone https://github.com/enviodev/hypersync-client-node.github cd hypersync-client-node/examples/all-erc20 npm install npm build npm start ``` -------------------------------- ### Install hypersync-client-node Source: https://github.com/enviodev/hypersync-client-node/blob/main/README.md Install the hypersync-client-node package using npm, pnpm, or yarn. ```bash # npm npm install @envio-dev/hypersync-client # pnpm pnpm add @envio-dev/hypersync-client # yarn yarn add @envio-dev/hypersync-client ``` -------------------------------- ### get Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves data from a specified source. ```APIDOC ## get ### Description Retrieves data from a specified source. ### Method get ### Parameters This method does not explicitly list parameters in the provided documentation. ``` -------------------------------- ### get Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves blockchain data for a single query. ```APIDOC ## get ### Description Get blockchain data for a single query ### Parameters #### Parameters - **query** (Query) - Description of query ### Returns Promise<[QueryResponse](../interfaces/QueryResponse.html)> ### Defined in [index.d.ts:89](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L89) ``` -------------------------------- ### Handling HeightStream Events Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/types/HeightStreamEvent.html Use a switch statement on 'event.type' to process different HeightStream events and their corresponding payloads. This example demonstrates how to log the height for a 'Height' event, a confirmation for a 'Connected' event, and details for a 'Reconnecting' event. ```typescript switch (event.type) { case "Height": console.log("Height:", event.height); break; case "Connected": console.log("Connected to stream"); break; case "Reconnecting": console.log("Reconnecting in", event.delayMillis, "ms", "due to error:", event.errorMsg); break; } ``` -------------------------------- ### constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Creates a new HypersyncClient instance with the provided configuration. ```APIDOC ## constructor ### Description Create a new client with given config ### Parameters #### Parameters - **cfg** (ClientConfig) - Description of cfg ### Returns - [HypersyncClient](HypersyncClient.html) ### Defined in [index.d.ts:68](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L68) ``` -------------------------------- ### constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Initializes a new instance of the Decoder class. ```APIDOC ## constructor ### Description Initializes a new instance of the Decoder class. ### Method constructor ### Returns - [Decoder](Decoder.html) ``` -------------------------------- ### newWithAgent Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Creates a new HypersyncClient instance with a specified agent. ```APIDOC ## newWithAgent ### Description Creates a new HypersyncClient instance with a specified agent. ### Method newWithAgent ### Parameters This method does not explicitly list parameters in the provided documentation. ``` -------------------------------- ### QueryResponseStream Constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/QueryResponseStream.html Initializes a new instance of the QueryResponseStream. ```APIDOC ## constructor ### Description Initializes a new instance of the QueryResponseStream. ### Returns - [QueryResponseStream](QueryResponseStream.html) ``` -------------------------------- ### Connect to Base Network Source: https://github.com/enviodev/hypersync-client-node/blob/main/README.md Instantiate HypersyncClient to connect to the Base network by specifying its URL. ```typescript // Base const client = new HypersyncClient({ url: "https://base.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); ``` -------------------------------- ### decodeLogs Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Decodes Ethereum logs asynchronously. ```APIDOC ## decodeLogs ### Description Decode logs asynchronously. ### Method decodeLogs(logs) ### Parameters #### Path Parameters * **logs** ([Log](../interfaces/Log.html)[]) - Description not available ### Returns Promise<[DecodedEvent](../interfaces/DecodedEvent.html)[][]> ### Response Example ```json { "example": "[DecodedEvent object array]" } ``` ``` -------------------------------- ### Utility Functions Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/modules.html Utility functions for common query presets and log level configuration. ```APIDOC ## Utility Functions ### `presetQueryBlocksAndTransactionHashes(options?: any): Query` Returns a preset query for blocks and transaction hashes. ### `presetQueryBlocksAndTransactions(options?: any): Query` Returns a preset query for blocks and transactions. ### `presetQueryLogs(options?: any): Query` Returns a preset query for logs. ### `presetQueryLogsOfEvent(options?: any): Query` Returns a preset query for logs of a specific event. ### `setLogLevel(level: string): void` Sets the logging level for the Hypersync client. ``` -------------------------------- ### decodeLogsSync Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Decodes Ethereum logs synchronously. ```APIDOC ## decodeLogsSync ### Description Decode logs synchronously. ### Method decodeLogsSync(logs) ### Parameters #### Path Parameters * **logs** ([Log](../interfaces/Log.html)[]) - Description not available ### Returns [DecodedEvent](../interfaces/DecodedEvent.html)[][] ``` -------------------------------- ### Connect to Base Network Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/index.html Connect to the Base network by specifying its URL in the HypersyncClient configuration. Ensure your API token is provided. ```typescript // Base const client = new HypersyncClient({ url: "https://base.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); ``` -------------------------------- ### ClientConfig Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/ClientConfig.html Defines the configuration object used to initialize the hypersync client. It includes settings for authentication, network requests, and retry mechanisms. ```APIDOC ## Interface: ClientConfig Configuration for the hypersync client. ### Properties * **apiToken** (string) - Required - HyperSync server api token. * **url** (string) - Required - The URL of the Hypersync server. * **enableChecksumAddresses** (boolean) - Optional - Enable checksum addresses in responses. * **enableQueryCaching** (boolean) - Optional - Whether to use query caching when using CapnProto serialization format. * **httpReqTimeoutMillis** (number) - Optional - Milliseconds to wait for a response before timing out. Default: 30000. * **maxNumRetries** (number) - Optional - Number of retries to attempt before returning error. Default: 12. * **proactiveRateLimitSleep** (boolean) - Optional - Whether to proactively sleep when the rate limit is exhausted instead of sending requests that will be rejected with 429. Default: true. * **retryBackoffMs** (number) - Optional - Milliseconds that would be used for retry backoff increasing. Default: 500. * **retryBaseMs** (number) - Optional - Initial wait time for request backoff. Default: 200. * **retryCeilingMs** (number) - Optional - Ceiling time for request backoff. Default: 5000. * **serializationFormat** (SerializationFormat) - Optional - The serialization format to use for requests and responses. ``` -------------------------------- ### url Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/ClientConfig.html Specifies the HyperSync server URL. This is a required string parameter for client configuration. ```APIDOC ## url ### Description Specifies the HyperSync server URL. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **url** (string) - The HyperSync server URL. ``` -------------------------------- ### Set ENVIO_API_TOKEN Source: https://github.com/enviodev/hypersync-client-node/blob/main/README.md Set your Envio API token as an environment variable to authenticate with HyperSync. ```bash export ENVIO_API_TOKEN="your-token-here" ``` -------------------------------- ### CallDecoder Constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/CallDecoder.html Initializes a new instance of the CallDecoder class. This is the entry point for using the decoder. ```APIDOC ## new CallDecoder() ### Description Initializes a new instance of the CallDecoder class. ### Returns - [CallDecoder](CallDecoder.html) ### Example ```typescript const decoder = new CallDecoder(); ``` ``` -------------------------------- ### StreamConfig Options Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/StreamConfig.html This section details the optional configuration parameters available for the StreamConfig interface, allowing fine-grained control over data fetching and streaming. ```APIDOC ## StreamConfig Options ### Description This interface defines optional parameters for configuring data streaming. These parameters allow users to control aspects like batch sizes, maximum number of items to fetch per request, response size targets, and the order of data retrieval. ### Parameters #### Optional Parameters - **minBatchSize** (number) - Optional - Hard lower clamp on the projected block count, to avoid tiny ranges. Default: 200. - **maxNumBlocks** (number) - Optional - Max number of blocks to fetch in a single request. - **maxNumTransactions** (number) - Optional - Max number of transactions to fetch in a single request. - **maxNumLogs** (number) - Optional - Max number of logs to fetch in a single request. - **maxNumTraces** (number) - Optional - Max number of traces to fetch in a single request. - **responseBytesTarget** (number) - Optional - Target response size in bytes. Each request's block span is projected from the most recently observed byte-density to aim each response at this size. Default: 400000. - **reverse** (boolean) - Optional - Stream data in reverse order. Default: false. ``` -------------------------------- ### Connect to Arbitrum Network Source: https://github.com/enviodev/hypersync-client-node/blob/main/README.md Instantiate HypersyncClient to connect to the Arbitrum network by specifying its URL. ```typescript // Arbitrum const client = new HypersyncClient({ url: "https://arbitrum.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); ``` -------------------------------- ### recv Method Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/QueryResponseStream.html Receives the next query response from the stream. ```APIDOC ## recv ### Description Receive the next query response from the stream. ### Method `recv()` ### Returns - Promise<[QueryResponse](../interfaces/QueryResponse.html)> ``` -------------------------------- ### presetQueryLogsOfEvent Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/functions/presetQueryLogsOfEvent.html Returns a query for all Logs within the block range from the given address with a matching topic0 event signature. Topic0 is the keccak256 hash of the event signature. If to_block is None then query runs to the head of the chain. ```APIDOC ## presetQueryLogsOfEvent ### Description Returns a query for all Logs within the block range from the given address with a matching topic0 event signature. Topic0 is the keccak256 hash of the event signature. If to_block is None then query runs to the head of the chain. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **contractAddress** (string) - Required - The address of the contract. - **topic0** (string) - Required - The keccak256 hash of the event signature. - **fromBlock** (number) - Required - The starting block number. - **toBlock** (number) - Optional - The ending block number. If not provided, the query runs to the head of the chain. ### Returns - **Query[]** - An array of Query objects. ``` -------------------------------- ### presetQueryLogs Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/functions/presetQueryLogs.html Returns a query object for all Logs within the block range from the given address. If to_block is None then query runs to the head of the chain. ```APIDOC ## presetQueryLogs ### Description Returns a query object for all Logs within the block range from the given address. If to_block is None then query runs to the head of the chain. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Method * N/A (SDK Function) ### Endpoint * N/A (SDK Function) ### Parameters #### Parameters * **contractAddress** (string) - Required - The address of the contract. * **fromBlock** (number) - Required - The starting block number. * **toBlock** (number) - Optional - The ending block number. If not provided, the query runs to the head of the chain. ### Returns #### Success Response * **Query[]** - An array of query objects for the specified logs. ### Returns Example * N/A (SDK Function Return Type) ``` -------------------------------- ### rateLimitInfo Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Provides information about the current rate limits. ```APIDOC ## rateLimitInfo ### Description Provides information about the current rate limits. ### Method rateLimitInfo ### Parameters This method does not take any parameters. ``` -------------------------------- ### HeightStream Constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HeightStream.html Initializes a new instance of the HeightStream class. ```APIDOC ## new HeightStream() ### Description Initializes a new HeightStream. ### Returns - **HeightStream**: A new instance of the HeightStream class. ``` -------------------------------- ### waitForRateLimit Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Waits until the current rate limit window resets. Returns immediately if no rate limit info is observed or if quota is available. ```APIDOC ## waitForRateLimit ### Description Wait until the current rate limit window resets. Returns immediately if no rate limit info observed or quota available. ### Method waitForRateLimit ### Returns Promise ``` -------------------------------- ### decodeEvents Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Decodes Ethereum events asynchronously. ```APIDOC ## decodeEvents ### Description Decode events asynchronously. ### Method decodeEvents(events) ### Parameters #### Path Parameters * **events** ([Event](../interfaces/Event.html)[]) - Description not available ### Returns Promise<[DecodedEvent](../interfaces/DecodedEvent.html)[][]> ### Response Example ```json { "example": "[DecodedEvent object array]" } ``` ``` -------------------------------- ### Connect to Arbitrum Network Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/index.html Connect to the Arbitrum network by specifying its URL in the HypersyncClient configuration. Ensure your API token is provided. ```typescript // Arbitrum const client = new HypersyncClient({ url: "https://arbitrum.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); ``` -------------------------------- ### fromSignatures Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Creates a new Decoder instance from a list of event signatures. ```APIDOC ## fromSignatures ### Description Create decoder from event signatures. ### Method fromSignatures(signatures) ### Parameters #### Path Parameters * **signatures** (string[]) - Description not available ### Returns [Decoder](Decoder.html) ``` -------------------------------- ### RateLimitInfo Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/RateLimitInfo.html Represents rate limit information obtained from server response headers. It includes optional properties for the consumed budget, total quota, remaining budget, and seconds until the rate limit window resets. ```APIDOC ## Interface: RateLimitInfo ### Description Rate limit information from server response headers. This interface outlines the properties related to the current rate limiting status. ### Properties - **cost** (number) - Optional - Budget consumed per request. - **limit** (number) - Optional - Total request quota for the current window. - **remaining** (number) - Optional - Remaining budget in the current window. - **resetSecs** (number) - Optional - Seconds until the rate limit window resets. ### Source * Defined in [index.d.ts:620](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L620) ``` -------------------------------- ### LogSelection Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/LogSelection.html Defines the structure for selecting logs using include and exclude filters. The 'include' filter is mandatory, while 'exclude' is optional. ```APIDOC ## Interface: LogSelection ### Description Selection criteria for logs with include and exclude filters. ### Properties #### include - **include** (LogFilter) - Required - Logs that match this filter will be included. #### exclude - **exclude** (LogFilter) - Optional - Logs that match this filter will be excluded. ### Type Definition ```typescript interface LogSelection { include: LogFilter; exclude?: LogFilter; } ``` ``` -------------------------------- ### decodeEventsSync Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Decodes Ethereum events synchronously. ```APIDOC ## decodeEventsSync ### Description Decode events synchronously. ### Method decodeEventsSync(events) ### Parameters #### Path Parameters * **events** ([Event](../interfaces/Event.html)[]) - Description not available ### Returns [DecodedEvent](../interfaces/DecodedEvent.html)[][] ``` -------------------------------- ### fromSignaturesWithChecksum Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/Decoder.html Creates a Decoder instance from event signatures with a checksum option. This method is static and belongs to the Decoder class. ```APIDOC ## fromSignaturesWithChecksum ### Description Creates a decoder from event signatures with a checksum option. ### Method Static method of the Decoder class. ### Parameters * **signatures** (string[]) - An array of event signature strings. * **checksum** (boolean) - A boolean indicating whether to enable checksumming for addresses. ### Returns * [Decoder](Decoder.html) - A new Decoder instance. ``` -------------------------------- ### HypersyncClient Class Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/modules.html The main class for interacting with the Hypersync client. It provides methods for querying and streaming blockchain data. ```APIDOC ## Class: HypersyncClient ### Description Provides methods to connect to the Hypersync service and stream blockchain data such as blocks, logs, and transactions. ### Methods #### `constructor(config: ClientConfig)` Initializes a new instance of the HypersyncClient. #### `query(query: Query): Promise>` Executes a query against the Hypersync service and returns the results. #### `stream(query: Query): QueryResponseStream` Opens a stream for real-time blockchain data based on the provided query. #### `close()` Closes the connection to the Hypersync service. ``` -------------------------------- ### getWithRateLimit Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves data from a specified source with rate limiting. ```APIDOC ## getWithRateLimit ### Description Retrieves data from a specified source with rate limiting. ### Method getWithRateLimit ### Parameters This method does not explicitly list parameters in the provided documentation. ``` -------------------------------- ### presetQueryBlocksAndTransactionHashes Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/functions/presetQueryBlocksAndTransactionHashes.html Returns a query object for all Blocks and hashes of the Transactions within the block range (from_block, to_block]. Also returns the block_hash and block_number fields on each Transaction so it can be mapped to a block. If to_block is None then query runs to the head of the chain. ```APIDOC ## presetQueryBlocksAndTransactionHashes(fromBlock, toBlock?) ### Description Returns a query object for all Blocks and hashes of the Transactions within the block range (from_block, to_block]. Also returns the block_hash and block_number fields on each Transaction so it can be mapped to a block. If to_block is None then query runs to the head of the chain. ### Parameters #### Path Parameters * **fromBlock** (number) - Required - The starting block number. * **toBlock** (number) - Optional - The ending block number. If not provided, the query runs to the head of the chain. ### Returns * [Query](../interfaces/Query.html)[] ``` -------------------------------- ### presetQueryBlocksAndTransactions Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/functions/presetQueryBlocksAndTransactions.html Generates a query for all Blocks and Transactions within the block range (from_block, to_block]. If to_block is None then query runs to the head of the chain. ```APIDOC ## presetQueryBlocksAndTransactions ### Description Returns a query for all Blocks and Transactions within the block range (from_block, to_block]. If to_block is None then query runs to the head of the chain. ### Parameters #### Path Parameters * **fromBlock** (number) - Required - The starting block number. * **toBlock** (number) - Optional - The ending block number. If not provided, the query extends to the latest block. ### Returns * [Query](../interfaces/Query.html)[] ``` -------------------------------- ### BlockSelection Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/BlockSelection.html Defines the structure for selecting blocks using include and exclude filters. The 'include' filter is mandatory, while 'exclude' is optional. ```APIDOC ## Interface: BlockSelection Selection criteria for blocks with include and exclude filters. ### Properties * **include** (BlockFilter) - Required - Blocks that match this filter will be included. * **exclude** (BlockFilter) - Optional - Blocks that match this filter will be excluded. ### Type Definition ```typescript interface BlockSelection { include: BlockFilter; exclude?: BlockFilter; } ``` ``` -------------------------------- ### Block Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/Block.html The Block interface defines the structure of an EVM block header, including various optional fields such as baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, nonce, number, parentHash, stateRoot, timestamp, and more. It also includes optional fields for withdrawals and their root. ```APIDOC ## Interface Block Evm block header object See ethereum rpc spec for the meaning of fields ```typescript interface Block { baseFeePerGas?: bigint; blobGasUsed?: bigint; difficulty?: bigint; excessBlobGas?: bigint; extraData?: string; gasLimit?: bigint; gasUsed?: bigint; hash?: string; l1BlockNumber?: number; logsBloom?: string; miner?: string; mixHash?: string; nonce?: bigint; number?: number; parentBeaconBlockRoot?: string; parentHash?: string; receiptsRoot?: string; sendCount?: string; sendRoot?: string; sha3Uncles?: string; size?: bigint; stateRoot?: string; timestamp?: number; totalDifficulty?: bigint; transactionsRoot?: string; uncles?: string[]; withdrawals?: Withdrawal[]; withdrawalsRoot?: string; } ``` ### Properties * **baseFeePerGas** (bigint) - Optional * **blobGasUsed** (bigint) - Optional * **difficulty** (bigint) - Optional * **excessBlobGas** (bigint) - Optional * **extraData** (string) - Optional * **gasLimit** (bigint) - Optional * **gasUsed** (bigint) - Optional * **hash** (string) - Optional * **l1BlockNumber** (number) - Optional * **logsBloom** (string) - Optional * **miner** (string) - Optional * **mixHash** (string) - Optional * **nonce** (bigint) - Optional * **number** (number) - Optional * **parentBeaconBlockRoot** (string) - Optional * **parentHash** (string) - Optional * **receiptsRoot** (string) - Optional * **sendCount** (string) - Optional * **sendRoot** (string) - Optional * **sha3Uncles** (string) - Optional * **size** (bigint) - Optional * **stateRoot** (string) - Optional * **timestamp** (number) - Optional * **totalDifficulty** (bigint) - Optional * **transactionsRoot** (string) - Optional * **uncles** (string[]) - Optional * **withdrawals** (Withdrawal[]) - Optional * **withdrawalsRoot** (string) - Optional ``` -------------------------------- ### rateLimitInfo Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves the most recently observed rate limit information. Returns null if no requests have been made yet. ```APIDOC ## rateLimitInfo ### Description Get the most recently observed rate limit information. Returns null if no requests have been made yet. ### Method rateLimitInfo ### Returns [RateLimitInfo](../interfaces/RateLimitInfo.html)\[] ``` -------------------------------- ### fromSignatures Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/CallDecoder.html Creates a CallDecoder instance from a list of function signatures. ```APIDOC ## fromSignatures ### Description Creates a call decoder from function signatures. ### Method Static ### Parameters #### Path Parameters * **signatures** (string[]) - Required - The function signatures to use for decoding. ### Returns * [CallDecoder](CallDecoder.html) ### Defined in [index.d.ts:6](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L6) ``` -------------------------------- ### Fetch USDT Transfer Events Source: https://github.com/enviodev/hypersync-client-node/blob/main/README.md Fetches ERC-20 Transfer event logs from a USDT contract on Ethereum using a preset query. Ensure your ENVIO_API_TOKEN is set. ```typescript import { HypersyncClient, presetQueryLogsOfEvent } from "@envio-dev/hypersync-client"; async function main() { const client = new HypersyncClient({ url: "https://eth.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); const usdtContract = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; // ERC-20 Transfer event topic0 const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; const query = presetQueryLogsOfEvent(usdtContract, transferTopic, 17_000_000, 17_000_050); const res = await client.get(query); console.log(`Found ${res.data.logs.length} Transfer events`); } main(); ``` -------------------------------- ### ColumnMapping Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/ColumnMapping.html Defines the structure for mapping columns to DataTypes for different data types like block, decoded logs, logs, traces, and transactions. ```APIDOC ## Interface: ColumnMapping Column mapping for stream function output. It lets you map columns you want into the DataTypes you want. ### Properties * **block** (Record) - Optional - Mapping for block data. * **decodedLog** (Record) - Optional - Mapping for decoded log data. * **log** (Record) - Optional - Mapping for log data. * **trace** (Record) - Optional - Mapping for trace data. * **transaction** (Record) - Optional - Mapping for transaction data. ### Example Usage (Conceptual) ```typescript interface ColumnMapping { block?: Record; decodedLog?: Record; log?: Record; trace?: Record; transaction?: Record; } // Example of how it might be used (not directly callable API) const myColumnMapping: ColumnMapping = { block: { 'block_number': 'number', 'block_hash': 'string' }, log: { 'log_message': 'string' } }; ``` ``` -------------------------------- ### Trace Interface Properties Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/Trace.html This snippet outlines the optional properties of the Trace interface, including their types and definitions. ```APIDOC ## Trace Interface Properties This section details the optional properties available for the Trace interface. ### `Optional` gasUsed - **Type**: `bigint` - **Description**: Represents the gas used by a trace. - **Defined in**: [index.d.ts:739](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L739) ### `Optional` init - **Type**: `string` - **Description**: Initialization data for a trace. - **Defined in**: [index.d.ts:731](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L731) ### `Optional` input - **Type**: `string` - **Description**: Input data for a trace. - **Defined in**: [index.d.ts:730](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L730) ### `Optional` output - **Type**: `string` - **Description**: Output data from a trace. - **Defined in**: [index.d.ts:740](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L740) ### `Optional` refundAddress - **Type**: `string` - **Description**: The address to refund in case of an error or specific conditions. - **Defined in**: [index.d.ts:749](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L749) ### `Optional` rewardType - **Type**: `string` - **Description**: The type of reward associated with the trace. - **Defined in**: [index.d.ts:734](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L734) ### `Optional` sighash - **Type**: `string` - **Description**: The sighash associated with the trace. - **Defined in**: [index.d.ts:750](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L750) ### `Optional` subtraces - **Type**: `number` - **Description**: The number of sub-traces associated with this trace. - **Defined in**: [index.d.ts:741](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L741) ### `Optional` to - **Type**: `string` - **Description**: The recipient address of the trace. - **Defined in**: [index.d.ts:727](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L727) ### `Optional` traceAddress - **Type**: `number[]` - **Description**: An array of numbers representing the trace address. - **Defined in**: [index.d.ts:742](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L742) ### `Optional` transactionHash - **Type**: `string` - **Description**: The hash of the transaction associated with the trace. - **Defined in**: [index.d.ts:743](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L743) ### `Optional` transactionPosition - **Type**: `number` - **Description**: The position of the trace within its transaction. - **Defined in**: [index.d.ts:744](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L744) ### `Optional` type - **Type**: `string` - **Description**: The type of the trace. - **Defined in**: [index.d.ts:745](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L745) ### `Optional` value - **Type**: `bigint` - **Description**: The value associated with the trace. - **Defined in**: [index.d.ts:732](https://github.com/enviodev/hypersync-client-node/blob/5f3a0a99042b4cd285ba4779ce0e188bd48b1cfc/index.d.ts#L732) ``` -------------------------------- ### Fetch ERC-20 Transfer Events Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/index.html Fetches ERC-20 Transfer event logs from a USDT contract on Ethereum within a specified block range. Ensure your ENVIO_API_TOKEN is set as an environment variable. ```typescript import { HypersyncClient, presetQueryLogsOfEvent } from "@envio-dev/hypersync-client"; async function main() { const client = new HypersyncClient({ url: "https://eth.hypersync.xyz", apiToken: process.env.ENVIO_API_TOKEN!, }); const usdtContract = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; // ERC-20 Transfer event topic0 const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; const query = presetQueryLogsOfEvent(usdtContract, transferTopic, 17_000_000, 17_000_050); const res = await client.get(query); console.log(`Found ${res.data.logs.length} Transfer events`); } main(); ``` -------------------------------- ### getWithRateLimit Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves blockchain data for a single query, including rate limit information. This method is useful for monitoring API usage. ```APIDOC ## getWithRateLimit ### Description Get blockchain data for a single query, with rate limit info. ### Method getWithRateLimit ### Parameters #### Query Parameters * **query** ([Query](../interfaces/Query.html)) - Required - The query object to filter data. ### Returns Promise<[QueryResponseWithRateLimit](../interfaces/QueryResponseWithRateLimit.html)\[] ``` -------------------------------- ### getHeight Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Retrieves the current block height. ```APIDOC ## getHeight ### Description Retrieves the current block height. ### Method getHeight ### Parameters This method does not take any parameters. ``` -------------------------------- ### EventStream Constructor Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/EventStream.html Initializes a new instance of the EventStream class. ```APIDOC ## new EventStream() ### Description Initializes a new instance of the EventStream class. ### Returns * [EventStream](EventStream.html) ``` -------------------------------- ### waitForRateLimit Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Waits until the rate limit allows further requests. ```APIDOC ## waitForRateLimit ### Description Waits until the rate limit allows further requests. ### Method waitForRateLimit ### Parameters This method does not take any parameters. ``` -------------------------------- ### Query Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/Query.html The Query interface allows users to specify criteria for retrieving blockchain data, including blocks, logs, transactions, and traces, along with field selection and join modes. ```APIDOC ## Interface Query Query for retrieving blockchain data ### Properties * **blocks?** (Array) - Optional - List of block selections, the query will return blocks that match any of these selections. * **fieldSelection** (FieldSelection) - Required - Field selection. The user can select which fields they are interested in, requesting less fields will improve query execution time and reduce the payload size so the user should always use a minimal number of fields. * **fromBlock** (number) - Required - The block to start the query from. * **includeAllBlocks?** (boolean) - Optional - Weather to include all blocks regardless of if they are related to a returned transaction or log. Normally the server will return only the blocks that are related to the transaction or logs in the response. But if this is set to true, the server will return data for all blocks in the requested range [from_block, to_block). * **joinMode?** (JoinMode) - Optional - Selects join mode for the query, Default: join in this order logs -> transactions -> traces -> blocks JoinAll: join everything to everything. For example if logSelection matches log0, we get the associated transaction of log0 and then we get associated logs of that transaction as well. Applites similarly to blocks, traces. JoinNothing: join nothing. * **logs?** (Array) - Optional - List of log selections, these have an or relationship between them, so the query will return logs that match any of these selections. * **maxNumBlocks?** (number) - Optional - Maximum number of blocks to return. * **maxNumLogs?** (number) - Optional - Maximum number of logs to return. * **maxNumTraces?** (number) - Optional - Maximum number of traces to return. * **maxNumTransactions?** (number) - Optional - Maximum number of transactions to return. * **toBlock?** (number) - Optional - The block to end the query at. * **traces?** (Array) - Optional - List of trace selections, the query will return traces that match any of these selections. * **transactions?** (Array) - Optional - List of transaction selections, the query will return transactions that match any of these selections. ``` -------------------------------- ### setLogLevel Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/functions/setLogLevel.html Sets the log level for the underlying Rust logger. This function should be called before creating any HypersyncClient instance. Only the first call to this function will take effect as the logger can only be initialized once per process. It accepts standard log levels like 'info', 'warn', 'debug', 'trace', 'error', or a custom filter directive such as 'hypersync_client=debug'. Note that if the RUST_LOG environment variable is set, it will take precedence over any value provided to this function. ```APIDOC ## Function setLogLevel ### Description Set the log level for the underlying Rust logger. Accepts values like "info", "warn", "debug", "trace", "error", or a full filter directive like "hypersync_client=debug". If RUST_LOG env var is set, it takes precedence. Must be called before creating any HypersyncClient. Only the first call takes effect (logger can only init once per process). ### Parameters #### Parameters * **level** (string) - Description of the log level to set. ### Returns * void ``` -------------------------------- ### decodeImpl Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/CallDecoder.html Decodes a single input string representing an Ethereum function call. ```APIDOC ## decodeImpl(input: string) ### Description Decodes a single input string representing an Ethereum function call. ### Parameters #### Path Parameters - **input** (string) - The input string to decode. ### Returns - [DecodedSolValue](../interfaces/DecodedSolValue.html)[] - An array of decoded values. ### Example ```typescript const decodedValue = decoder.decodeImpl('0xa9059cbb0000000000000000000000000000000000000000000000000000000000000001'); ``` ``` -------------------------------- ### fromSignatures Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/CallDecoder.html Creates a CallDecoder instance from a list of function signatures. This method is asynchronous. ```APIDOC ## fromSignatures(signatures: string[]) ### Description Creates a CallDecoder instance from a list of function signatures asynchronously. ### Parameters #### Path Parameters - **signatures** (string[]) - An array of function signatures. ### Returns - Promise<[CallDecoder](CallDecoder.html)> - A promise that resolves to a new CallDecoder instance. ### Example ```typescript const decoder = await CallDecoder.fromSignatures(['transfer(address,uint256)', 'approve(address,uint256)']); ``` ``` -------------------------------- ### FieldSelection Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/FieldSelection.html Defines the structure for selecting specific fields for different data types. Users can optionally include fields for blocks, logs, traces, or transactions. ```APIDOC ## Interface: FieldSelection ### Description Allows for the selection of specific fields to be returned for each data type. ### Properties - **block** (BlockField[]) - Optional - Block fields to include in the response. - **log** (LogField[]) - Optional - Log fields to include in the response. - **trace** (TraceField[]) - Optional - Trace fields to include in the response. - **transaction** (TransactionField[]) - Optional - Transaction fields to include in the response. ### Example Usage ```typescript const selection: FieldSelection = { block: [ "hash", "number" ], transaction: [ "hash", "from", "to" ] }; ``` ``` -------------------------------- ### Event Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/Event.html Represents a single event (log) with associated block and transaction data. ```APIDOC ## Interface: Event Data relating to a single event (log). ### Properties * **block** (Block) - Optional - Block that this event happened in. * **log** (Log) - Required - Evm log data. * **transaction** (Transaction) - Optional - Transaction that triggered this event. ``` -------------------------------- ### TraceSelection Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/TraceSelection.html Defines the structure for trace selection criteria, specifying which traces to include and exclude based on filters. ```APIDOC ## Interface: TraceSelection ### Description Selection criteria for traces with include and exclude filters. This interface allows you to define rules for filtering traces, specifying which ones should be included and which ones should be excluded. ### Properties #### `include` (TraceFilter) - Required Traces that match this filter will be included. This is a mandatory property for defining the primary selection criteria. #### `exclude` (TraceFilter) - Optional Traces that match this filter will be excluded. This property can be used to further refine the selection by specifying traces that should not be processed, even if they match the include filter. ### Example Usage (Conceptual) ```typescript const selectionCriteria: TraceSelection = { include: { // Define include filter criteria here, e.g., by service name, operation, or tags serviceName: 'user-service', operationName: 'GET /users/:id' }, exclude: { // Define exclude filter criteria here, e.g., to ignore health checks operationName: '/health' } }; ``` ``` -------------------------------- ### QueryResponseWithRateLimit Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/QueryResponseWithRateLimit.html Represents a response from a query that includes rate limit information. This interface is crucial for understanding API usage limits and handling rate-limited requests. ```APIDOC ## Interface: QueryResponseWithRateLimit ### Description Response from a query that includes rate limit information. This interface provides details about API rate limits and the actual query response. ### Properties #### rateLimit - **rateLimit** (RateLimitInfo) - Required - Rate limit information from response headers. #### response - **response** (QueryResponse) - Optional - The query response data. This field is `null` when the request was rate limited (HTTP 429). In such cases, inspect the `rate_limit` information and retry the request later. ``` -------------------------------- ### collect Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/HypersyncClient.html Collects data from a specified source. ```APIDOC ## collect ### Description Collects data from a specified source. ### Method collect ### Parameters This method does not explicitly list parameters in the provided documentation. ``` -------------------------------- ### serializationFormat Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/ClientConfig.html Defines the serialization format for HTTP requests. Defaults to JSON if not specified. ```APIDOC ## serializationFormat ### Description Query serialization format to use for HTTP requests. Default: Json. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **serializationFormat** (SerializationFormat[]) - The serialization format to use for HTTP requests. ``` -------------------------------- ### LogFilter Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/LogFilter.html Defines the structure for filtering logs by address and topics. The 'address' property filters logs by contract address, and the 'topics' property filters logs by event topics. Both properties are optional. ```APIDOC ## Interface LogFilter Filter for selecting logs based on address and topics ### Properties #### `Optional` address - **Type**: `string[]` - **Description**: Address of the contract, any logs that has any of these addresses will be returned. Empty means match all. #### `Optional` topics - **Type**: `string[][]` - **Description**: Topics to match, each member of the top level array is another array, if the nth topic matches any topic specified in topics[n] the log will be returned. Empty means match all. ``` -------------------------------- ### EventResponse Interface Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/interfaces/EventResponse.html This interface represents the response structure for an event query. It includes the event data, information about the next block for pagination, and the total execution time of the query. Optionally, it can include the archive height and a rollback guard. ```APIDOC ## Interface: EventResponse Response from an event query ### Properties * **archiveHeight** (number) - Optional - Current height of the source hypersync instance. * **data** ([Event](Event.html)[]) - Required - Response data. * **nextBlock** (number) - Required - Next block to query for. The responses are paginated, so the caller should continue the query from this block if they didn't get responses up to the to_block they specified in the Query. * **rollbackGuard** ([RollbackGuard](RollbackGuard.html)) - Optional - Rollback guard, supposed to be used to detect rollbacks. * **totalExecutionTime** (number) - Required - Total time it took the hypersync instance to execute the query. ``` -------------------------------- ### decodeTracesInputSync Source: https://github.com/enviodev/hypersync-client-node/blob/main/docs/classes/CallDecoder.html Synchronously decodes an array of trace input data. ```APIDOC ## decodeTracesInputSync(traces: Trace[]) ### Description Decode trace inputs synchronously. ### Parameters #### Path Parameters - **traces** ([Trace](../interfaces/Trace.html)[]) - An array of trace objects to decode. ### Returns - [DecodedSolValue](../interfaces/DecodedSolValue.html)[][] - An array of decoded value arrays. ### Example ```typescript const decodedTraces = decoder.decodeTracesInputSync([{ from: '0x...', to: '0x...', input: '0xa9059cbb...' }]); ``` ```