Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit cabc9f6

Browse files
committed
explain how filter work on target network, and add complex example.
1 parent 54dd289 commit cabc9f6

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

docs/hooks/useScaffoldEventHistory.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ useScaffoldEventHistory({
8787
});
8888
```
8989

90-
Key Points to Consider
90+
In this example, we added two filters. The hook will then send an RPC request to the target network with these filter parameters. The response will only include the events that match the filters. (setter is `0x00daC9BCF0bC21a9f3483D47A8Ade4764EE5c0377B3bCDDf2df477E3C1e55810` and event_type is `9987n`)
91+
92+
**Key Points to Consider**
9193

9294
1. Filter Keys: The keys in the `filters` object must correspond to event fields annotated with `#[key]`.
9395
2. Filter Values: The value of a filter can be an array, meaning the event value can match any element in the array. For example:
@@ -120,3 +122,69 @@ struct GreetingChanged {
120122
```
121123

122124
During serialization, keys are serialized in the order they are defined in the event. When applying filters, if new_greeting is not provided but bool_val and size_val are, these filter conditions will be ignored.
125+
126+
Then let's see a more complex example. the event defined with complex data type.
127+
128+
```rust
129+
#[derive(Drop, starknet::Event)]
130+
struct GreetingChanged {
131+
#[key]
132+
greeting_setter: ContractAddress,
133+
#[key]
134+
new_greeting: ByteArray,
135+
#[key]
136+
event_type: u256,
137+
premium: bool,
138+
value: u256,
139+
#[key]
140+
addresses: Array<ContractAddress>,
141+
arr: Array<u256>,
142+
#[key]
143+
tup: (u32, u64, bool, ContractAddress),
144+
#[key]
145+
st: SomeStruct,
146+
#[key]
147+
enum_val: SomeEnum,
148+
#[key]
149+
bool_val: bool,
150+
}
151+
```
152+
153+
If we want to add all the filters, the hook definition will be:
154+
155+
```javascript
156+
useScaffoldEventHistory({
157+
contractName: "YourContract",
158+
eventName: "contracts::YourContract::YourContract::GreetingChanged",
159+
fromBlock: 0n,
160+
filters: {
161+
greeting_setter: "0x00daC9BCF0bC21a9f3483D47A8Ade4764EE5c0377B3bCDDf2df477E3C1e55810",
162+
new_greeting: "hello world",
163+
event_type: 9987n,
164+
addresses: [
165+
"0x00daC9BCF0bC21a9f3483D47A8Ade4764EE5c0377B3bCDDf2df477E3C1e55810",
166+
"0x065Dc4A1C484bcde864e7eEBc55F033F2BAF57dc6e2f4eaE14c6860836CFcd0E",
167+
],
168+
tup: {
169+
0: 1n,
170+
1: 2n,
171+
2: true,
172+
3: caller,
173+
},
174+
st: {
175+
addr: new CairoOption(CairoOptionVariant.Some, caller),
176+
val: new CairoOption(CairoOptionVariant.None),
177+
},
178+
enum_val: new CairoCustomEnum({
179+
val1: new CairoCustomEnum({
180+
val1: 12,
181+
}),
182+
}),
183+
bool_val: true,
184+
},
185+
});
186+
```
187+
188+
Please pay attention to how tuples, structs, and enum types are defined on the web side.
189+
190+
> There is a limitation on the filter count. The count here refers to the number of elements in the serialization result of the filter object. The maximum allowed count is 16.

0 commit comments

Comments
 (0)