Skip to main content

getEvents

A builder function that returns the interaction to get events.

Events are emitted by Cadence code during transaction execution and provide insights into what happened during execution. This function queries for events of a specific type within a range of block heights.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.getEvents(eventType, start, end)

Or import directly the specific function:


_10
import { getEvents } from "@onflow/sdk"
_10
_10
getEvents(eventType, start, end)

Usage


_12
import * as fcl from "@onflow/fcl";
_12
_12
// Get FlowToken transfer events from blocks 1000 to 2000
_12
const events = await fcl.send([
_12
fcl.getEvents("A.1654653399040a61.FlowToken.TokensDeposited", 1000, 2000)
_12
]).then(fcl.decode);
_12
_12
console.log("Found events:", events.length);
_12
events.forEach(event => {
_12
console.log("Event data:", event.data);
_12
console.log("Transaction ID:", event.transactionId);
_12
});

Parameters

eventType

  • Type: string
  • Description: The type of event to get (e.g., "A.1654653399040a61.FlowToken.TokensWithdrawn")

start

  • Type: number
  • Description: The start block height to query from

end

  • Type: number
  • Description: The end block height to query to

Returns

InteractionBuilderFn


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


Rate this page