getEvents
Action for getting Starknet contract events.
Import
import { getEvents } from "starkweb/core";
Usage
index.ts
import { getEvents } from "starkweb/core";
import { config } from "./config";
const events = await getEvents(config, {
address: "0x123...",
fromBlock: 1000n,
toBlock: 2000n,
});
Parameters
import { type GetEventsParameters } from "starkweb/core";
address (optional)
Hex
The contract address to get events for.
fromBlock (optional)
bigint
The block number to start getting events from.
toBlock (optional)
bigint
The block number to stop getting events at.
index.ts
import { getEvents } from "starkweb/core";
import { config } from "./config";
const events = await getEvents(config, {
address: "0x123...",
fromBlock: 1000n,
toBlock: 2000n,
});
chainId (optional)
Hex | undefined
The chain ID to get events from. If not provided, uses the current chain.
index.ts
import { getEvents } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
const events = await getEvents(config, {
address: "0x123...",
chainId: mainnet.chain_id,
});
Return Type
import { type GetEventsReturnType } from "starkweb/core";
Returns an array of events and chain ID:
events
Event[]
Array of events matching the filter criteria.
chainId
Hex
The chain ID of the network.
Example
example.ts
import { getEvents } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains";
import { config } from "./config";
// Get events on current chain
const events = await getEvents(config, {
address: "0x123...",
fromBlock: 1000n,
toBlock: 2000n,
});
console.log("Events found:", events.length);
// Get events on specific chain
const mainnetEvents = await getEvents(config, {
address: "0x123...",
fromBlock: 1000n,
chainId: mainnet.chain_id,
});
Error
import { type GetEventsErrorType } from "starkweb/core";