Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watch on useScaffoldEventHistory #38

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/hooks/useScaffoldEventHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 4

# useScaffoldEventHistory

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

```ts
const {
Expand All @@ -16,14 +16,17 @@ const {
eventName: "GreetingChange",
// Specify the starting block number from which to read events, this is a bigint.
fromBlock: 31231n,
blockData: true,
// 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).
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`](/deploying/deploy-nextjs-app#--pollinginterval) (set at `scaffold.config.ts`).
2 changes: 1 addition & 1 deletion docs/hooks/useScaffoldEventSubscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ useScaffoldEventSubscriber({
});
```

This example subscribes to the `GreetingChange` event emitted by the `YourContract` smart contract and logs the parameters from the event to the console when it's emitted. The `listener` function accepts an array of `logs` that occurred during the [ `pollingInterval`](/deploying/deploy-nextjs-app#--pollinginterval) and each array items contains an `args` property which can be destructured to get the parameters emitted by the event, this function can customized according to your needs.
This example subscribes to the `GreetingChange` event emitted by the `YourContract` smart contract and logs the parameters from the event to the console when it's emitted. The `listener` function accepts an array of `logs` that occurred during the [`pollingInterval`](/deploying/deploy-nextjs-app#--pollinginterval) (set at `scaffold.config.ts`) and each array items contains an `args` property which can be destructured to get the parameters emitted by the event, this function can customized according to your needs.

:::note

Expand Down