Skip to content

AlgoKit Subscriber TypeScript

Subscribe to the Algorand blockchain with a simple, flexible TypeScript library

Version 3 of AlgoKit Subscriber targets algosdk@3 and @algorandfoundation/algokit-utils@9, both of which are peer dependencies you install alongside it:

Terminal window
npm install algosdk@^3.0.0 @algorandfoundation/algokit-utils@^9.0.0 @algorandfoundation/algokit-subscriber

If you need to target algosdk@2, use version 2 of the subscriber instead: npm install algosdk@^2.10.0 @algorandfoundation/algokit-utils@^7.1.0 @algorandfoundation/algokit-subscriber@^2.2.0.

import { AlgorandClient } from '@algorandfoundation/algokit-utils'
import { AlgorandSubscriber } from '@algorandfoundation/algokit-subscriber'
import { TransactionType } from 'algosdk'
const algorand = AlgorandClient.testNet()
const subscriber = new AlgorandSubscriber(
{
filters: [
{
name: 'filter1',
filter: {
type: TransactionType.pay,
sender: 'ABC...',
},
},
],
maxRoundsToSync: 100,
syncBehaviour: 'skip-sync-newest',
watermarkPersistence: {
get: async () => 0n,
set: async (watermark) => { /* save watermark */ },
},
},
algorand.client.algod,
algorand.client.indexer,
)
// Set up subscription(s)
subscriber.on('filter1', async (transaction) => {
// ...
})
// Set up error handling
subscriber.onError((e) => {
// ...
})
// Either: Start the subscriber (if in long-running process)
subscriber.start()
// OR: Poll the subscriber (if in cron job / periodic lambda)
await subscriber.pollOnce()

Real-time Subscriptions

Subscribe to transactions at the tip of the chain with low-latency processing.

Indexing & Catchup

Build indexes from the beginning of the chain with fast indexer catchup.

ARC-28 Events

Subscribe to and process ARC-28 events from smart contract calls.

Resilient Watermarking

Persist watermarks for reliable at-least-once delivery across outages.