@apibara/protocol
This package contains the client used to stream data from Apibara.
Install the package from npm:
This example shows how to connect to the StarkNet stream and stream all
Ethereum ERC20 token Transfer
events.
Start by importing the types and classes used by this example.
Then create the filter object. The filter is used to
ask the stream for specific data, in this case the stream will only contain
events matching the given key (the Transfer
event) and emitted from the given
smart contract.
Then create the client, specifying the authorization token created in the Apibara dashboard.
If you're connecting to a local instance of Apibara you need to disable SSL.
You can specify gRPC options using the clientOptions
argument:
The client needs to send its configuration to the server, we can do this with the configure
method.
This method accepts a filter (each stream type has a different filter), a batch size and the requested data finality.
Apibara sends historical data in batches to maximize performance, the batch size can be tweaked to optimize syncing speed.
Finally, we can iterate over the async stream generated by the client. Each message contains a batch of data.
The data contained in a batch is specific to each stream.
Apibara is the fastest platform to build production-grade indexers that connect onchain data to web2 services.
Resources