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:
_10import * as sdk from "@onflow/sdk"_10_10sdk.subscribeEvents(options)
Or import directly the specific function:
_10import { subscribeEvents } from "@onflow/sdk"_10_10subscribeEvents(options)
Usage
_23import * as fcl from "@onflow/fcl";_23_23// Subscribe to FlowToken transfer events_23const 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_23const 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
- Type:
EventFilter
Returns
InteractionBuilderFn
_10export type InteractionBuilderFn = (_10 ix: Interaction_10) => Interaction | Promise<Interaction>