Skip to main content

getEvents

Get a list of a specific event emitted from the contract during a specified time period.

Usage

Provide the name of the event, and an optional filter to define the time period to get events for.

// The name of the event to get logs for
const eventName = "Transfer";

const events = await contract.events.getEvents(eventName);

Configuration

eventName

The name of the event to get logs for.

In Solidity, an event is triggered by the emit keyword.

Example.sol
// An example Solidity contract
emit Transfer(); // Triggering event

To listen to this event, use the name of the event as it appears in the contract.

const events = await contract.events.getEvents(
"Transfer",
);

filters (optional)

An optional object containing the fromBlock and toBlock numbers for the time period to get events for.

The order field indicates the ordering of the events; desc (descending) or asc (ascending).

The filters field allows you to filter on indexed event parameters.

The default fromBlock is 0 and the default toBlock is latest.

const options = {
fromBlock: 0,
toBlock: 1000000,
order: "desc",
filters: {
from: "0x...",
to: "0x...",
},
};

const events = await contract.events.getEvents(eventName, options);

Return Value

Returns an array of ContractEvent objects, containing the following properties:

{
eventName: string;
data: TEvent;
transaction: {
blockNumber: number;
blockHash: string;
transactionIndex: number;
removed: boolean;
address: string;
data: string;
topics: Array<string>;
transactionHash: string;
logIndex: number;
}
}
[];