Skip to main content

useScaffoldEventHistory

Use this hook to retrieve historical event logs for your smart contract, providing past activity data, with the option to watch for new events.

const {
data: events,
isLoading: isLoadingEvents,
error: errorReadingEvents,
} = useScaffoldEventHistory({
contractName: "YourContract",
eventName: "GreetingChange",
// Specify the starting block number from which to read events, this is a bigint.
fromBlock: 31231n,
// If set to true, the events will be updated every pollingInterval milliseconds set at scaffoldConfig (default: false)
watch: true,
// Apply filters to the event based on parameter names and values { [parameterName]: value },
filters: { premium: true },
// If set to true it will return the block data for each event (default: false)
blockData: true,
// If set to true it will return the transaction data for each event (default: false),
transactionData: true,
// If set to true it will return the receipt data for each event (default: false),
receiptData: true,
});

This example retrieves the historical event logs for the GreetingChange event of the YourContract smart contract, starting from block number 31231 and filtering events where the premium parameter is true. The data property of the returned object contains an array of event objects, each containing the event parameters and (optionally) the block, transaction, and receipt data. The isLoading property indicates whether the event logs are currently being fetched, and the error property contains any error that occurred during the fetching process (if applicable). Since watch is set to true, the event logs will be refetched every pollingInterval milliseconds (set at scaffoldConfig.config.ts).