Skip to main content
V2 gateway requests require an API key. Set SQD_API_KEY in .env before running gateway-based examples, or pass apiKey: process.env.SQD_API_KEY in GatewaySettings.

setFields(options)

Set the fields to be retrieved for data items of each supported type. The options object has the following structure:
Every field selector is a collection of boolean fields, typically (with a notable exception of trace field selectors) mapping one-to-one to the fields of data items within the batch context iterables. Defining a field of a field selector of a given type and setting it to true will cause the processor to populate the corresponding field of all data items of that type. Here is a definition of a processor that requests gas and value fields for transactions:
Same fields will be available for all data items of any given type, including nested items. Suppose we used the processor defined above to subscribe to some transactions as well as some logs, and for each log we requested a parent transaction:
As a result, gas and value fields would be available both within the transaction items of the transactions iterable of block data and within the transaction items that provide parent transaction information for the logs:
Some data fields, like hash for transactions, are enabled by default but can be disabled by setting a field of a field selector to false. For example, this code will not compile:
Disabling unused fields will improve sync performance, as the disabled fields will not be fetched from the SQD Network gateway.

Data item types and field selectors

Most IDEs support smart suggestions to show the possible field selectors. For VS Code, press Ctrl+Space.
Here we describe the data item types as functions of the field selectors. Unless otherwise mentioned, each data item type field maps to the eponymous field of its corresponding field selector. Item fields are divided into three categories:
  • Fields that are added independently of the setFields() call. These are either fixed or depend on the related data retrieval flags (e.g. transaction for logs).
  • Fields that can be disabled by setFields(). E.g. a topics field will be fetched for logs by default, but can be disabled by setting topics: false within the log field selector.
  • Fields that can be requested by setFields(). E.g. a transactionHash field will only be available in logs if the log field selector sets transactionHash: true.

Logs

Log data items may have the following fields:
See the block headers section for the definition of BlockHeader and the transactions section for the definition of Transaction.

Transactions

Transaction data items may have the following fields:
status field contains the value returned by eth_getTransactionReceipt: 1 for successful transactions, 0 for failed ones and undefined for chains and block ranges not compliant with the post-Byzantinum hard fork EVM specification (e.g. 0-4,369,999 on Ethereum). type field is populated similarly. For example, on Ethereum 0 is returned for Legacy txs, 1 for EIP-2930 and 2 for EIP-1559. Other networks may have a different set of types. See the block headers section for the definition of BlockHeader. l1* fields can only be requested for networks from this list. Requesting them for other networks may cause HTTP 500 responses.

State diffs

StateDiff data items may have the following fields:
The meaning of the kind field values is as follows:
  • '=': no change has occurred;
  • '+': a value was added;
  • '*': a value was changed;
  • '-': a value was removed.
The values of the key field are regular hexadecimal contract storage key strings or one of the special keys 'balance' | 'code' | 'nonce' denoting ETH balance, contract code and nonce value associated with the state diff. See the block headers section for the definition of BlockHeader and the transactions section for the definition of Transaction.

Traces

Field selection for trace data items is somewhat more involved because its fixed fields action and result may contain different fields depending on the value of the type field. The retrieval of each one of these subfields is configured independently. For example, to ensure that all traces of 'call' type contain the .action.gas field, the processor must be configured as follows:
The full Trace type with all its possible (sub)fields looks like this:
Every trace also exposes getTransaction(), getParent(), and children. The corresponding transaction and parent properties are optional because related data must be requested explicitly.

Block headers

BlockHeader data items may have the following fields:
The l1BlockNumber field can only be requested for networks from this list. Requesting it for other networks may cause HTTP 500 responses.

A complete example