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

Commit d1a4926

Browse files
committed
add hooks
1 parent 936c4e4 commit d1a4926

File tree

4 files changed

+83
-17
lines changed

4 files changed

+83
-17
lines changed

docs/components/CustomConnectButton.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Scaffold-Stark 2 uses a custom _"Connect Button"_, that is enhanced with several
1212

1313
You can extend this component to suit your app's needs.
1414

15-
![CustomConnectButton Example](/img/RainbowKitCustomConnectButton.gif)
15+
![CustomConnectButton Example](/img/customConnectButton.gif)
1616

1717
## Import
1818

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# useScaffoldMultiContractWrite
6+
7+
Use this hook to send multiple transactions to your smart contracts to write data or perform actions.
8+
9+
```ts
10+
const { writeAsync: writeMultipleContractsAsync } = useScaffoldMultiContractWrite({
11+
calls: [
12+
{
13+
contractName: "YourContract1",
14+
functionName: "setGreeting",
15+
args: ["Hello"],
16+
},
17+
{
18+
contractName: "YourContract2",
19+
functionName: "setCounter",
20+
args: [42],
21+
},
22+
],
23+
});
24+
```
25+
26+
This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The writeAsync function (writeMultipleContractsAsync instance) sends the transactions to the smart contracts.
27+
28+
## Usage Example
29+
30+
```tsx
31+
<button
32+
className="btn btn-primary"
33+
onClick={async () => {
34+
try {
35+
await writeMultipleContractsAsync();
36+
} catch (e) {
37+
console.error("Error sending transactions:", e);
38+
}
39+
}}
40+
>
41+
Send Transactions
42+
</button>
43+
```
44+
45+
This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The writeAsync function (writeMultipleContractsAsync instance) sends the transactions to the smart contracts.
46+
47+
## Configuration
48+
49+
| Parameter | Type | Description |
50+
| :--------------------- | :------------------------------------------------------------ | :---------------------------------------------------------------------------------- |
51+
| **calls** | `Array<UseScaffoldWriteConfig<TContractName, TFunctionName>>` | An array of calls, each containing the contract name, function name, and arguments. |
52+
| **options** (optional) | `InvocationsDetails` | Additional options for the transactions. |
53+
54+
## Call Object Configuration
55+
56+
| Parameter | Type | Description |
57+
| :------------------ | :---------- | :--------------------------------------------------------------------------------------------------------------- |
58+
| **contractName** | `string` | Name of the contract to write to. |
59+
| **functionName** | `string` | Name of the function to call. |
60+
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. |
61+
62+
You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite).
63+
64+
## Return Values
65+
66+
- `writeContractAsync` function sends the transaction to the smart contract.
67+
- `isMining` property indicates whether the transaction is currently being mined.
68+
- The extended object includes properties inherited from the useContractWrite hook from starknet-react. You can check the [usecontractwrite return values](https://wagmi.sh/react/api/hooks/useWriteContract#return-type) for the types.

docs/hooks/useScaffoldReadContract.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ This example retrieves the data returned by the `userGreetingCounter` function o
1818

1919
## Configuration
2020

21-
| Parameter | Type | Description |
22-
| :------------------- | :---------- | :------------------------------------------------------------------------------------------------------------------ |
23-
| **contractName** | `string` | Name of the contract to read from. |
24-
| **functionName** | `string` | Name of the function to call. |
25-
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. |
26-
| **blockIdentifier** (optional) | `BlockNumber` | Block identifier to use (default: pending). |
27-
| **watch** (optional) | `boolean` | Watches and refreshes data on new blocks. (default : `true`) |
28-
| Other arguments | `various` | You can pass other arguments accepted by the useContractRead hook from @starknet-react/core. |
29-
21+
| Parameter | Type | Description |
22+
| :----------------------------- | :------------ | :--------------------------------------------------------------------------------------------------------------- |
23+
| **contractName** | `string` | Name of the contract to read from. |
24+
| **functionName** | `string` | Name of the function to call. |
25+
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. |
26+
| **blockIdentifier** (optional) | `BlockNumber` | Block identifier to use (default: pending). |
27+
| **watch** (optional) | `boolean` | Watches and refreshes data on new blocks. (default : `true`) |
28+
| Other arguments | `various` | You can pass other arguments accepted by the useContractRead hook from @starknet-react/core. |
3029

3130
You can also pass other arguments accepted by [useReadContract wagmi hook](https://wagmi.sh/react/api/hooks/useReadContract#parameters).
3231

docs/hooks/useScaffoldWriteContract.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ Below is the configuration for `writeContractAsync` function:
4242

4343
## Configuration
4444

45-
| Parameter | Type | Description |
46-
| :--------------------------------- | :---------- | :------------------------------------------------------------------------------------------------------------------- |
47-
| **contractName** | `string` | Name of the contract to write to. |
48-
| **functionName** | `string` | Name of the function to call.|
49-
| **args** (optional) | `unknown[]` |Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. |
50-
| **options** (optional) | `objet` | Additional options for the transaction (e.g., value for payable functions).|
51-
45+
| Parameter | Type | Description |
46+
| :--------------------- | :---------- | :--------------------------------------------------------------------------------------------------------------- |
47+
| **contractName** | `string` | Name of the contract to write to. |
48+
| **functionName** | `string` | Name of the function to call. |
49+
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. |
50+
| **options** (optional) | `objet` | Additional options for the transaction (e.g., value for payable functions). |
5251

5352
You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite).
5453

0 commit comments

Comments
 (0)