-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cursorrules
More file actions
2360 lines (1790 loc) · 69.8 KB
/
.cursorrules
File metadata and controls
2360 lines (1790 loc) · 69.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Scaffold-Stark 2 Development Assistant
<project_overview>
Everything you need to build dApps on Starknet. A modern, clean version of Scaffold-Stark with NextJS, Starknet-React, Starknet.js and TypeScript. Supports Starknet Foundry for Cairo smart contracts.
</project_overview>
<smart_contract_patterns>
<read_operations>
- Read: useScaffoldReadContract (packages/nextjs/hooks/scaffold-stark/useScaffoldReadContract.ts)
</read_operations>
<write_operations>
- Write: useScaffoldWriteContract (packages/nextjs/hooks/scaffold-stark/useScaffoldWriteContract.ts)
- Multi-Write: useScaffoldMultiWriteContract (packages/nextjs/hooks/scaffold-stark/useScaffoldMultiWriteContract.ts)
</write_operations>
<event_operations>
- Event Listening: useScaffoldWatchContractEvent for real-time events (packages/nextjs/hooks/scaffold-stark/useScaffoldWatchContractEvent.ts)
- Event History: useScaffoldEventHistory for historical data (packages/nextjs/hooks/scaffold-stark/useScaffoldEventHistory.ts)
</event_operations>
<note>
You have all the details of our custom hooks in the Hooks section from this file.
</note>
</smart_contract_patterns>
<component_guidelines>
<instruction>
Use Scaffold-Stark 2 components whenever it makes sense, they are located in `packages/nextjs/components/scaffold-stark`. You have all the details about components in the Components section from this file.
</instruction>
</component_guidelines>
<ui_design_system>
<styling_framework>
- Base: Tailwind CSS v3
- Components: daisyUI v4
- DaisyUI Documentation: https://daisyui.com/llms.txt
</styling_framework>
<implementation>
- Core theme configuration: packages/nextjs/tailwind.config.ts
- Base styling: packages/nextjs/styles/globals.css
- Component-specific styling in individual component files
</implementation>
</ui_design_system>
<wallet_connection>
<supported>Starknet-React with multiple wallet connectors (packages/nextjs/services/web3/connectors.tsx)</supported>
<custom_connect_button>packages/nextjs/components/scaffold-stark/CustomConnectButton/index.tsx</custom_connect_button>
</wallet_connection>
<deployment_and_network_setup>
<default_chains>devnet, sepolia, mainnet (from @starknet-react/chains)</default_chains>
<configuration>
- Chains: Configured in packages/nextjs/scaffold.config.ts via the targetNetworks array
- RPC: Configured via environment variables (NEXT_PUBLIC_DEVNET_PROVIDER_URL, NEXT_PUBLIC_SEPOLIA_PROVIDER_URL, NEXT_PUBLIC_MAINNET_PROVIDER_URL)
- Provider setup: packages/nextjs/services/web3/provider.ts
</configuration>
<network_config_example>
```typescript
// In scaffold.config.ts
import { Chain } from "@starknet-react/chains";
import { supportedChains as chains } from "./supportedChains";
const scaffoldConfig = {
targetNetworks: [chains.devnet], // Can be devnet, sepolia, mainnet
pollingInterval: 30000,
onlyLocalBurnerWallet: true,
walletAutoConnect: true,
autoConnectTTL: 86_400_000, // 24 hours
} as const satisfies ScaffoldConfig;
```
</network_config_example>
</deployment_and_network_setup>
<disable_type_linting_error_checks>
<source>https://www.scaffoldstark.com/docs/disable-type-linting-error-checks</source>
<overview>
TypeScript helps you catch errors at compile time, which can save time and improve code quality, but can be challenging for those who are new to the language or who are used to the more dynamic nature of JavaScript. These sections show the steps required to disable type & lint checks on different levels.
</overview>
<disabling_commit_checks>
<description>
We run the `pre-commit` git hook which lints the staged files and doesn't let you commit if there is an linting error.
</description>
<instructions>
To disable this, go to the `.husky/pre-commit` file and comment out `yarn lint-staged --verbose`
```diff
- yarn lint-staged --verbose
+ # yarn lint-staged --verbose
```
</instructions>
</disabling_commit_checks>
<deploying_to_vercel_without_checks>
<description>
By default, Vercel runs type and lint checks before building your app. The deployment will fail if there are any type or lint errors.
</description>
<cli_deployment>
To ignore these checks while deploying from the CLI, use:
```shell
yarn vercel:yolo
```
</cli_deployment>
<environment_variable>
If your repo is connected to Vercel, you can set `NEXT_PUBLIC_IGNORE_BUILD_ERROR` to `true` in an environment variable.
</environment_variable>
</deploying_to_vercel_without_checks>
<disabling_github_workflow>
<description>
We have a GitHub workflow setup checkout `.github/workflows/lint.yaml` which runs type and lint error checks every time code is pushed to `main` branch or pull request is made to `main` branch.
</description>
<instructions>
To disable it, delete `.github` directory.
</instructions>
</disabling_github_workflow>
</disable_type_linting_error_checks>
<components>
<overview>
Scaffold-Stark 2 provides a set of pre-built components for common Starknet use cases. You can make use of them to accelerate and simplify your dapp development.
</overview>
<address_component>
<source>https://www.scaffoldstark.com/docs/components/Address</source>
<description>
Display a Starknet address along with a utility icon to copy the address. If the address is associated with a Starknet ID that has an avatar, this avatar will be displayed. If not, a blockie image representation of the address will be shown.
By default, the component will show the Starknet ID name (if available) and the address.
You can also choose to display only the Starknet ID name (if available) or the address, by setting the `onlyEnsOrAddress` prop to `true`.
Clicking on the address redirects to the connected wallet's network block explorer. If the wallet is not connected, it redirects to the block explorer of `targetNetworks[0]`. You can disable this behaviour with the `disableAddressLink` prop.
</description>
<import_statement>
```tsx
import { Address } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
<Address address="0x034aA3F359A9D614239015126635CE7732c18fDF3" />
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **address** | `string` | `undefined` | Address in `0x___` format, it will resolve its Starknet ID if it has one associated. |
| **disableAddressLink** (optional) | `boolean` | `false` | Set it to `true` to disable the blockexplorer link behaviour when clicking on the address. |
| **format** (optional) | `string` | `"short"` | By default, only the first five characters of the address are displayed. Set this to `"long"` to display the entire address. |
| **size** (optional) | `string` | `"base"` | Size for the displayed Address component. `base` by default but you can pass in `xs`, `sm`, `base`, `lg`, `xl`, `2xl`, `3xl`. |
| **onlyEnsOrAddress** (optional) | `boolean` | `false` | When `true`, displays only the Starknet ID name (if available) or the address, not both. |
</props>
</address_component>
<address_input_component>
<source>https://www.scaffoldstark.com/docs/components/AddressInput</source>
<description>
Display a Starknet address input that validates the address format, resolves Starknet ID domains, and shows their avatars.
Also shows a blockie image for each address.
</description>
<import_statement>
```tsx
import { AddressInput } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
const [address, setAddress] = useState("");
```
```tsx
<AddressInput
onChange={setAddress}
value={address}
placeholder="Input your address"
/>
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **value** | `string` | `undefined` | A Starknet address in (`0x___` format) or a Starknet ID domain. |
| **onChange** | `function` | `undefined` | A callback invoked when the data in the address input changes. |
| **placeholder** (optional) | `string` | `undefined` | The string that will be rendered before address input has been entered. |
| **name** (optional) | `string` | `undefined` | Helps identify the data being sent if AddressInput is submitted into a form. |
| **disabled** (optional) | `boolean` | `false` | If `true`, sets the address input un-clickable and unusable. |
</props>
</address_input_component>
<balance_component>
<source>https://www.scaffoldstark.com/docs/components/Balance</source>
<description>
Displays the balance of a given address in both STRK and US dollars (USD).
</description>
<import_statement>
```tsx
import { Balance } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
<Balance address="0x034aA3F359A9D614239015126635CE7732c18fDF3" />
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **address** | `string` | `undefined` | Address in `0x___` format, it will resolve its Starknet ID if it has one associated. |
| **className** (optional) | `string` | `""` | Prop to pass additional CSS styling to the component. You can use Tailwind / daisyUI classes like `text-3xl` for styling. |
</props>
</balance_component>
<blockie_avatar_component>
<source>https://www.scaffoldstark.com/docs/components/BlockieAvatar</source>
<description>
Show a blockie (bar code profile icon) component for a given Starknet address.
If a Starknet ID profile picture is available, prefer rendering that image in the parent and fallback to `BlockieAvatar` otherwise. `BlockieAvatar` itself always renders a blo-generated identicon for the provided address.
If you want more control over styling the blockie, you can directly use blo (pre-installed in Scaffold-Stark 2) and internally used by `BlockieAvatar` component to get the image URL.
</description>
<import_statement>
```tsx
import { BlockieAvatar } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
<BlockieAvatar
address="0x034aA3F359A9D614239015126635CE7732c18fDF3"
size={24}
/>
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| `address` | `string` | `undefined` | The address for which you want to display its blockie. Ensure it's in the `0x___` format. |
| `size` | `number` | `undefined` | Width and Height in pixels (square). |
</props>
</blockie_avatar_component>
<avatar_component>
<description>
Reusable avatar component that renders a Starknet ID profile picture when provided; otherwise falls back to a blo-generated blockie for the given address.
</description>
<import_statement>
```tsx
import { Avatar } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
<Avatar
address="0x034aA3F359A9D614239015126635CE7732c18fDF3"
size={30}
profilePicture={profile?.profilePicture}
/>
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| `address` | `string` | `undefined` | The address used to render a fallback blockie if no profile picture is available. Must be in `0x___` format. |
| `size` | `number` | `undefined` | Width and Height in pixels (square). |
| `profilePicture` (optional) | `string` | `undefined` | Starknet ID profile picture URL. If present, it will be rendered. |
| `className` (optional) | `string` | `undefined` | Extra class names applied to the rendered image. |
</props>
</avatar_component>
<stark_input_component>
<source>https://www.scaffoldstark.com/docs/components/StarkInput</source>
<description>
Displays an input field for STRK/USD amount, with an option to convert between STRK and USD.
</description>
<import_statement>
```tsx
import { StarkInput } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
const [strkAmount, setStrkAmount] = useState("");
```
```tsx
<StarkInput value={strkAmount} onChange={(amount) => setStrkAmount(amount)} />
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **value** | `string` | `undefined` | You can enter STRK quantity or USD quantity, but value will always be stored in STRK. |
| **onChange** | `function` | `undefined` | A callback invoked when the amount in the StarkInput changes. |
| **placeholder** (optional) | `string` | `undefined` | The string that will be rendered when there is no input value. |
| **name** (optional) | `string` | `undefined` | Helps identify the data being sent if StarkInput is submitted into a form. |
| **disabled** (optional) | `boolean` | `false` | When set to `true`, changes input background color and border to have disabled styling. |
</props>
</stark_input_component>
<input_base_component>
<source>https://www.scaffoldstark.com/docs/components/InputBase</source>
<description>
Simple building block for creating an input which comes with basic default styles (colors, rounded borders).
</description>
<import_statement>
```tsx
import { InputBase } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
const [url, setUrl] = useState<string>();
```
```tsx
<InputBase name="url" placeholder="url" value={url} onChange={setUrl} />
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **value** | `string` | `undefined` | The data that your input will show. |
| **onChange** | `function` | `undefined` | A callback invoked when the data in the input changes. |
| **placeholder** (optional) | `string` | `undefined` | The string that will be rendered before input data has been entered. |
| **name** (optional) | `string` | `undefined` | Helps identify the data being sent if InputBase is submitted into a form. |
| **error** (optional) | `boolean` | `false` | When set to `true`, changes input border to have error styling. |
| **disabled** (optional) | `boolean` | `false` | When set to `true`, changes input background color and border to have disabled styling. |
</props>
</input_base_component>
<integer_input_component>
<source>https://www.scaffoldstark.com/docs/components/IntegerInput</source>
<description>
Provides an input field for integer values, validating that user input is a valid integer, and showing error if not.
Shows by default a small button to multiply input's value * 10^18 to transform to wei.
</description>
<import_statement>
```tsx
import { IntegerInput } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
const [txValue, setTxValue] = useState<string | bigint>("");
```
```tsx
<IntegerInput
value={txValue}
onChange={(updatedTxValue) => {
setTxValue(updatedTxValue);
}}
placeholder="value (wei)"
/>
```
</usage_example>
<props>
| Prop | Type | Default Value | Description |
|------|------|---------------|-------------|
| **value** | `string` | `undefined` | The data that your input will show. |
| **onChange** | `function` | `undefined` | A callback invoked when the amount in the input changes. |
| **placeholder** (optional) | `string` | `undefined` | The string that will be rendered before input data has been entered. |
| **name** (optional) | `string` | `undefined` | Helps identify the data being sent if InputBase is submitted into a form. |
| **error** (optional) | `boolean` | `false` | When set to `true`, changes input border to have error styling. |
| **disabled** (optional) | `boolean` | `false` | When set to `true`, changes input background color and border to have disabled styling. |
</props>
</integer_input_component>
<custom_connect_button>
<source>https://www.scaffoldstark.com/docs/components/CustomConnectButton</source>
<description>
Scaffold-Stark 2 uses a custom "Connect Button", based on Starknet-React, that is enhanced with several useful features:
- **Balance Display**: Shows the balance of STRK from the connected address.
- **Chain Name and Color**: Displays the name of the connected Starknet network and uses a distinct color for each chain.
- **Custom Modal**: Includes copy address feature, view its QR code, access address details in blockexplorer, and disconnect.
You can extend this component to suit your app's needs.
</description>
<import_statement>
```tsx
import { CustomConnectButton } from "~~/components/scaffold-stark";
```
</import_statement>
<usage_example>
```tsx
<CustomConnectButton />
```
</usage_example>
</custom_connect_button>
</components>
<hooks>
<overview>
Scaffold-Stark 2 provides a collection of custom React hooks designed to simplify interactions with your deployed smart contracts. These hooks are wrappers around Starknet-React, an easy-to-use interface with typescript autocompletions for reading from, writing to, and monitoring events emitted by your smart contracts.
To ensure autocompletions function correctly, always update the `targetNetworks` in `scaffold.config.ts` to include the relevant network/chain whenever you deploy your contract using `yarn deploy --network`.
</overview>
<important_files>
The custom hooks rely on three main files for their functionality and TypeScript autocompletion:
- `packages/nextjs/contracts/deployedContracts.ts`
- `packages/nextjs/contracts/externalContracts.ts`
- `scaffold.config.ts`
The `deployedContracts.ts` file is auto-generated/updated whenever you run `yarn deploy --network`. It organizes contract addresses and abi's based on chainId.
</important_files>
<multiple_chains_note>
When having multiple chains configured in `targetNetworks`, make sure to have same contractName's on other chains as `targetNetworks[0].id`. This ensures proper functionality and autocompletion of custom hooks, as the current setup and types assumes that same contract's are present on other chains as `targetNetworks[0]`.
</multiple_chains_note>
<use_deployed_contract_info>
<source>https://www.scaffoldstark.com/docs/hooks/useDeployedContractInfo</source>
<description>
Use this hook to fetch details about a deployed smart contract, including the ABI and address.
</description>
<usage_example>
```ts
const { data: deployedContractData } = useDeployedContractInfo({
contractName: "YourContract",
});
```
This example retrieves the details of the deployed contract with the specified name and stores the details in the `deployedContractData` object.
</usage_example>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract. |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to `targetNetworks[0].id` |
</configuration>
<return_value>
- `data`: Object containing `address` and `abi` of contract.
</return_value>
</use_deployed_contract_info>
<use_scaffold_contract>
<source>https://www.scaffoldstark.com/docs/hooks/useScaffoldContract</source>
<description>
Use this hook to get your contract instance by providing the contract name. It enables you to interact with your contract methods.
For reading data or sending transactions, it's recommended to use `useScaffoldReadContract` and `useScaffoldWriteContract`.
</description>
<usage_example>
```ts
const { data: yourContract } = useScaffoldContract({
contractName: "YourContract",
});
// Returns the greeting and can be called in any function, unlike useScaffoldReadContract
await yourContract?.call("greeting");
// Used to write to a contract and can be called in any function
import { useAccount } from "@starknet-react/core";
const { account } = useAccount();
const { data: yourContract } = useScaffoldContract({
contractName: "YourContract",
});
const setGreeting = async () => {
if (account && yourContract) {
yourContract.connect(account);
// Call the method in any function
await yourContract.invoke("set_greeting", ["the greeting here"]);
}
};
```
This example uses the `useScaffoldContract` hook to obtain a contract instance for the `YourContract` smart contract.
</usage_example>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract. |
</configuration>
<return_value>
- `data` : Object representing Starknet.js's contract instance. Which can be used to call `call` and `invoke` methods of the contract.
- `isLoading` : Boolean indicating if the contract is being loaded.
</return_value>
</use_scaffold_contract>
<use_scaffold_event_history>
<source>https://www.scaffoldstark.com/docs/hooks/useScaffoldEventHistory</source>
<description>
Use this hook to retrieve historical event logs for your smart contract, providing past activity data, with the option to watch for new events.
</description>
<usage_example>
```ts
const {
data: events,
isLoading: isLoadingEvents,
error: errorReadingEvents,
} = useScaffoldEventHistory({
contractName: "YourContract",
eventName: "GreetingChanged",
fromBlock: 31231n,
watch: true,
filters: { greeting_setter: "0x9eB2C4866aAe575bC88d00DE5061d5063a1bb3aF" },
blockData: true,
transactionData: true,
receiptData: true,
});
```
This example retrieves the historical event logs for the `GreetingChanged` event of the `YourContract` smart contract, starting from block number 31231 and filtering events where the `greeting_setter` parameter is `0x9eB2C4866aAe575bC88d00DE5061d5063a1bb3aF`.
</usage_example>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract to read from. |
| **eventName** | `string` | Name of the event to read. |
| **fromBlock** | `bigint` | Block number from which to start reading events. |
| **toBlock** | `bigint` | block number to stop reading events at (if not provided, reads until current block) |
| **filters** (optional) | `object` | Apply filters to the event based on **indexed** parameter names and values `{ [parameterName]: value }`. |
| **blockData** (optional) | `boolean` | If set to true it will return the block data for each event (default: false). |
| **transactionData** (optional) | `boolean` | If set to true it will return the transaction data for each event (default: false). |
| **receiptData** (optional) | `boolean` | If set to true it will return the receipt data for each event (default: false). |
| **watch** (optional) | `boolean` | If set to true, the events will be refetched every `pollingInterval` set at `scaffold.config.ts`. (default: false). |
| **enabled** (optional) | `boolean` | If set to false, the hook will not fetch any data (default: true). |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to `targetNetworks[0].id` |
| **blocksBatchSize** (optional) | `number` | batch size for fetching events. If specified, each batch will contain at most this many blocks (default: 500) |
</configuration>
<return_values>
- `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.
- `isLoading` property indicates whether the event logs are currently being fetched.
- `error` property contains any error that occurred during the fetching process (if applicable).
</return_values>
</use_scaffold_event_history>
<use_scaffold_read_contract>
<source>https://www.scaffoldstark.com/docs/hooks/useScaffoldReadContract</source>
<description>
Use this hook to read public variables and get data from read-only functions of your smart contract.
</description>
<usage_example>
```ts
const { data: totalCounter } = useScaffoldReadContract({
contractName: "YourContract",
functionName: "user_greeting_counter",
args: ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045"],
});
```
This example retrieves the data returned by the `user_greeting_counter` function of the `YourContract` smart contract.
</usage_example>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract to read from. |
| **functionName** | `string` | Name of the function to call. |
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters |
| **watch** (optional) | `boolean` | Watches and refreshes data on new blocks. (default : `true`) |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to `targetNetworks[0].id` |
</configuration>
<additional_parameters>
You can also pass other arguments accepted by useReadContract starknet-react hook.
</additional_parameters>
<return_values>
- The retrieved data is stored in the `data` property of the returned object.
- You can refetch the data by calling the `refetch` function.
- The extended object includes properties inherited from starknet-react useReadContract. You can check the useReadContract return values documentation to check the types.
</return_values>
</use_scaffold_read_contract>
<use_scaffold_watch_contract_event>
<source>https://www.scaffoldstark.com/docs/hooks/useScaffoldWatchContractEvent</source>
<description>
Use this hook to subscribe to events emitted by your smart contract, and receive real-time updates when these events are emitted.
</description>
<usage_example>
```ts
useScaffoldWatchContractEvent({
contractName: "YourContract",
eventName: "GreetingChanged",
// The onLogs function is called whenever a GreetingChanged event is emitted by the contract.
// Parameters emitted by the event can be destructed using the below example
// for this example: event GreetingChanged(greeting_setter: ContractAddress, new_greeting: felt252, premium: bool, value: u256);
onLogs: (logs) => {
logs.map((log) => {
const { greeting_setter, value, premium, new_greeting } = log.args;
console.log(
"📡 GreetingChanged event",
greeting_setter,
value,
premium,
new_greeting,
);
});
},
});
```
This example subscribes to the `GreetingChanged` event emitted by the `YourContract` smart contract and logs the parameters from the event to the console when it's emitted.
This hook is a wrapper around starknet-react's useWatchContractEvent.
</usage_example>
<rpc_provider_note>
Due to shortcomings of some RPC providers, this hook may or may not fire events always. To update the RPC link checkout the RPC configuration section.
</rpc_provider_note>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract to read from. |
| **eventName** | `string` | Name of the event to read. |
| **onLogs** | `function` | Callback function to execute when the event is emitted. Accepts an array of `logs` that occurred during the `pollingInterval` set at `scaffold.config.ts`. Each array item contains an `args` property, which can be destructured to get the parameters emitted by the event. This function can customized according to your needs. |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to `targetNetworks[0].id` |
</configuration>
<state_management_note>
It is recommended to `setState` using updater function in the `onLogs` function to avoid problems due to caching.
</state_management_note>
</use_scaffold_watch_contract_event>
<use_scaffold_write_contract>
<source>https://www.scaffoldstark.com/docs/hooks/useScaffoldWriteContract</source>
<description>
Use this hook to send a transaction to your smart contract to write data or perform an action.
</description>
<usage_example>
```ts
const { sendAsync: writeYourContractAsync } = useScaffoldWriteContract({
contractName: "YourContract",
functionName: "set_greeting",
args: ["Hello World!"],
});
```
The following configuration options can be passed to the hook:
</usage_example>
<configuration>
| Parameter | Type | Description |
|-----------|------|-------------|
| **contractName** | `string` | Name of the contract to write to. |
| **functionName** | `string` | Name of the function to call. |
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters. |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to `targetNetworks[0].id` |
</configuration>
<send_transaction_example>
To send the transaction, you can call the `sendAsync` function returned by the hook (which we instance as `writeYourContractAsync`). Here's an example usage:
```tsx
<button
className="btn btn-primary"
onClick={async () => {
try {
await writeYourContractAsync();
} catch (e) {
console.error("Error setting greeting:", e);
}
}}
>
Set Greeting
</button>
```
This example sends a transaction to the `YourContract` smart contract to call the `set_greeting` function with the arguments passed to the hook. The `sendAsync` function (`writeYourContractAsync` instance) sends the transaction to the smart contract.
You can also override arguments when calling:
```tsx
await writeYourContractAsync({ args: ["New Greeting!"] });
```
</send_transaction_example>
<return_values>
- `sendAsync` function sends the transaction to the smart contract.
- `isLoading` property indicates whether the transaction is currently being processed.
- The extended object includes properties inherited from starknet-react useSendTransaction. You can check the useSendTransaction return values documentation to check the types.
</return_values>
</use_scaffold_write_contract>
<use_transactor>
<source>https://www.scaffoldstark.com/docs/hooks/useTransactor</source>
<description>
Use this hook to interact with the Starknet network and give UI feedback on the transaction status.
Any error will show a popup with nice error message.
</description>
<usage_example>
```ts
const transactor = useTransactor();
const writeTx = transactor.writeTransaction;
const calls = [
{
contractAddress: "0x97843608a00e2bbc75ab0C1911387E002565DEDE",
entrypoint: "transfer",
calldata: ["0x123...", "1000000000000000000", "0"],
},
];
await writeTx(calls);
```
This example tries to send a transaction with the provided calls, prompting the connected wallet for a signature. And in the case of a successful transaction, it will show a popup in the UI with the message: "🎉 Transaction completed successfully!".
You can pass in an array of calls to be executed in a single transaction. It also supports Cairo 1.0 multicall functionality.
</usage_example>
<configuration_use_transactor>
| Parameter | Type | Description |
|-----------|------|-------------|
| **\_walletClient** (optional) | `AccountInterface` | The wallet client that should sign the transaction. Defaults to the connected account from useAccount |
</configuration_use_transactor>
<configuration_write_transaction>
| Parameter | Type | Description |
|-----------|------|-------------|
| **calls** | `Call[]` | Array of calls to execute in the transaction. Each call should contain contractAddress, entrypoint, and calldata. |
| **options** (optional) | `object` | Additional options for the transaction. |
</configuration_write_transaction>
<return_values_use_transactor>
- `writeTransaction`: Function that is used to send transactions with UI feedback.
- `sendTransactionInstance`: The underlying useSendTransaction instance.
- `transactionReceiptInstance`: The transaction receipt data.
</return_values_use_transactor>
<return_values_write_transaction>
- A promise that resolves with the transaction hash once the transaction is submitted.
</return_values_write_transaction>
</use_transactor>
</hooks>
<recipes>
<overview>
Explore a collection of practical recipes to implement common web3 use-cases with Scaffold-Stark 2. Learn how to interact with smart contracts, read and display data, manage account balances, and more. Each recipe offers step-by-step guidance, making it easy to implement different blockchain features into your dApps.
</overview>
<add_custom_chain_recipe>
<source>https://www.scaffoldstark.com/docs/recipes/add-custom-chain</source>
<title>Add a custom chain</title>
<description>
This recipe demonstrates how to add a custom chain to your project. We'll use a custom Starknet network as an example, but you can apply this process to any other Starknet-compatible network you want to add.
Scaffold-Stark 2 uses @starknet-react/chains as a list of chains.
Normally, devnet, sepolia, and mainnet already exist in @starknet-react/chains and you can import them and use them, but we're going to add a custom network manually to show you how to do it.
</description>
<note>
Scaffold-Stark 2 consists of two parts:
- `packages/nextjs`: nextjs frontend
- `packages/snfoundry`: starknet foundry to deploy smart contracts
The frontend and the snfoundry project use a different set of chains.
You should add the chain to both the frontend and your snfoundry config. Checkout deploying your smart contract section on how to deploy to different chains.
By doing this, you will be able to deploy the contracts to the chain you added and interact with them from the frontend.
</note>
<step_1>
<title>Define the chain</title>
<instructions>
First, create a new file called `customChains.ts` in your `packages/nextjs/utils/` directory.
Open the file with your favorite editor and add the following code to define the chain.
</instructions>
<code_example>
```typescript title="packages/nextjs/utils/customChains.ts"
import { Chain } from "@starknet-react/chains";
// Custom Starknet chain
export const customStarknet: Chain = {
id: "0x534e5f43555354444d", // SN_CUSTOM in hex
network: "custom",
name: "Custom Starknet",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
rpcUrls: {
default: {
http: ["https://your-custom-rpc-endpoint.com"],
},
public: {
http: ["https://your-custom-rpc-endpoint.com"],
},
},
blockExplorers: {
default: {
name: "Custom Explorer",
url: "https://your-custom-explorer.com",
},
},
testnet: true, // or false if it's mainnet
};
```
In this file, we're defining a custom Starknet chain. You can add as many chains as you want to the `customChains.ts` file.
</code_example>
</step_1>
<step_2>
<title>Update `scaffold.config.ts`</title>
<instructions>
Next, update your `scaffold.config.ts` file to include the new chain:
</instructions>
<code_example>
```typescript title="packages/nextjs/scaffold.config.ts"
import { customStarknet } from "./utils/customChains";
// ... other imports and type definitions
const scaffoldConfig = {
targetNetworks: [customStarknet],
// ... other configuration options
} as const satisfies ScaffoldConfig;
export default scaffoldConfig;
```
If you'd like to add multiple chains, you can do so by adding them to the `targetNetworks` array. Below is a simple example of how to add multiple chains.
```typescript title="packages/nextjs/scaffold.config.ts"
import { customStarknet, anotherCustomChain } from "./utils/customChains";
const scaffoldConfig = {
targetNetworks: [customStarknet, anotherCustomChain],
// ... other configuration options
} as const satisfies ScaffoldConfig;
```
</code_example>
</step_2>
</add_custom_chain_recipe>
<get_current_balance_recipe>
<source>https://www.scaffoldstark.com/docs/recipes/GetCurrentBalanceFromAccount</source>
<title>Get the Current Balance of the Connected Account</title>
<description>
This recipe shows how to fetch and display the STRK balance of the currently connected account.
</description>
<full_code_example>
```tsx title="components/ConnectedAddressBalance.tsx"