Skip to main content

subscribeEvents

Subscribe to events with the given filter and parameters.

Creates a subscription to listen for real-time events from the Flow blockchain. This function configures the subscription parameters for filtering specific events based on type, addresses, contracts, and other criteria.

Events are emitted by Cadence code during transaction execution and provide insights into what happened. Subscriptions allow you to listen for these events in real-time without polling.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.subscribeEvents(options)

Or import directly the specific function:


_10
import { subscribeEvents } from "@onflow/sdk"
_10
_10
subscribeEvents(options)

Usage


_23
import * as fcl from "@onflow/fcl";
_23
_23
// Subscribe to FlowToken transfer events
_23
const subscription = await fcl.send([
_23
fcl.subscribeEvents({
_23
eventTypes: [
_23
"A.1654653399040a61.FlowToken.TokensWithdrawn",
_23
"A.1654653399040a61.FlowToken.TokensDeposited"
_23
],
_23
startHeight: 1000000, // Start from specific block height
_23
heartbeatInterval: 3000 // 3 second heartbeat
_23
})
_23
]);
_23
_23
// Subscribe to events from specific contracts
_23
const contractSubscription = await fcl.send([
_23
fcl.subscribeEvents({
_23
contracts: ["FlowToken", "FungibleToken"],
_23
addresses: ["0x1654653399040a61"]
_23
})
_23
]);
_23
_23
// Handle the subscription data elsewhere using fcl.subscribe()

Parameters

options

Returns

InteractionBuilderFn


_10
export type InteractionBuilderFn = (
_10
ix: Interaction
_10
) => Interaction | Promise<Interaction>


Rate this page