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

Commit b0c1008

Browse files
Update useScaffoldWriteContract.md
1 parent 52eebc5 commit b0c1008

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

docs/hooks/useScaffoldWriteContract.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@ sidebar_position: 2
77
Use this hook to send a transaction to your smart contract to write data or perform an action.
88

99
```ts
10-
const { writeContractAsync: writeYourContractAsync } = useScaffoldWriteContract("YourContract");
10+
const { writeAsync: writeYourContractAsync } = useScaffoldContractWrite({
11+
contractName: "YourContract",
12+
functionName: "setGreeting",
13+
args: ["The value to set"],
14+
});
1115
```
1216

13-
The first argument is name of the contract to write to and the second argument is wagmi's `useWriteContract` hook [parameters object](https://wagmi.sh/react/api/hooks/useWriteContract#parameters).
17+
The first argument is name of the contract to write to and the second argument is starknet-react `useWriteContract` hook [parameters object](https://starknet-react.com/hooks/mutation/usecontractwrite).
1418

15-
To send the transaction, you can call the `writeContractAsync` function returned by the hook (which we instance as `writeYourContractAsync`). Here's an example usage:
19+
## Usage Example
1620

1721
```tsx
1822
<button
1923
className="btn btn-primary"
2024
onClick={async () => {
2125
try {
2226
await writeYourContractAsync({
23-
functionName: "setGreeting",
24-
args: ["The value to set"],
25-
value: parseEther("0.1"),
27+
args: ["The new value to set"],
28+
options: {
29+
value: parseEther("0.1"),
30+
},
2631
});
2732
} catch (e) {
2833
console.error("Error setting greeting:", e);
@@ -33,24 +38,22 @@ To send the transaction, you can call the `writeContractAsync` function returned
3338
</button>
3439
```
3540

36-
This example sends a transaction to the `YourContract` smart contract to call the `setGreeting` function with the arguments passed in `args`. The `writeContractAsync` function (`writeYourContractAsync` instance) sends the transaction to the smart contract.
37-
3841
Below is the configuration for `writeContractAsync` function:
3942

4043
## Configuration
4144

4245
| Parameter | Type | Description |
4346
| :--------------------------------- | :---------- | :------------------------------------------------------------------------------------------------------------------- |
44-
| **functionName** | `string` | Name of the function to call. |
45-
| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if accepts any). Types are inferred from contract's function parameters. |
46-
| **value** (optional) | `bigint` | Amount of ETH to send with the transaction (for payable functions only). |
47-
| **onBlockConfirmation** (optional) | `function` | Callback function to execute when the transaction is confirmed. |
48-
| **blockConfirmations** (optional) | `number` | Number of block confirmations to wait for before considering transaction to be confirmed (default : 1). |
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+
4952

50-
You can also pass other arguments accepted by [writeContractAsync from wagmi](https://wagmi.sh/react/api/hooks/useWriteContract#mutate-async).
53+
You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite).
5154

5255
## Return Values
5356

5457
- `writeContractAsync` function sends the transaction to the smart contract.
5558
- `isMining` property indicates whether the transaction is currently being mined.
56-
- The extended object includes properties inherited from wagmi useWriteContract. You can check the [useWriteContract return values](https://wagmi.sh/react/api/hooks/useWriteContract#return-type) documentation to check the types.
59+
- The extended object includes properties inherited from the useContractWrite hook from starknet-react. You can check the [useWriteContract return values](https://wagmi.sh/react/api/hooks/useWriteContract#return-type) for the types.

0 commit comments

Comments
 (0)