Apibara Blog

News and updates about Apibara

Follow us on Twitter

31 Dec 2022

Apibara protocol v1alpha2 preview

Today we release a preview of the next version of the Apibara protocol, also known as v1alpha2. We are excited for this release to bring many new features that improve developer experience and performance. For the first time, developers have a powerful API to stream any on-chain data directly into their application.

const address = FieldElement.fromBigInt(
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'
)
const transferKey = [FieldElement.fromBigInt(hash.getSelectorFromName('Transfer'))]
const filter = Filter.create()
.addEvent((ev) =>
ev.withFromAddress(address)
.withKeys(transferKey))
.withStateUpdate((su) =>
su.addStorageDiff((st) => st.withContractAddress(address)))
.encode()
const client = new StreamClient({
url: 'mainnet.starknet.a5a.ch',
}).connect()
client.configure({
filter,
batchSize: 20,
finality: v1alpha2.DataFinality.DATA_STATUS_FINALIZED
})
for await (const message of client) {
if (message.data && message.data?.data) {
handleBatch(client, message.data.endCursor, message.data.data)
}
}

The most significant change of this release is that developers can now decide what type of data to receive, including:

  • transactions, filtered by transaction type and parameters like sender or class hash,
  • events, filtered by contract address, keys and event data,
  • state updates, including changes in storage variables.

The protocol optimizes data for developer happiness and efficiency. For example, events include their transaction and transaction receipt since this data is often accessed together.

Developers can now choose three levels of data finality:

  • Finalized: only receive finalized data that will always be valid. On StarkNet, this means data accepted on L1.
  • Accepted: receive data from the canonical chain and notifications about chain reorganizations.
  • Pending: like accepted, but also receive pending data before they are produced.

You can start playing with the new protocol today, connecting to the streams directly using gRPC o using the Typescript SDK. The alpha 2 version deployed today supports finalized data only. In the upcoming weeks, we will release an update that achieves feature parity with the current protocol.

The new streams are available at the following addresses:

  • mainnet.starknet.a5a.ch: StarkNet mainnet
  • goerli.starknet.a5a.ch: StarkNet Goerli testnet

Open-source on-chain data streaming platform secured by Zero Knowledge proofs.

Resources

Blog

© 2023 GNC Labs Limited. All rights reserved.