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 passing args imperatively to writeAsync example #32

Merged
merged 1 commit into from
Oct 27, 2023
Merged
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
14 changes: 11 additions & 3 deletions docs/hooks/useScaffoldContractWrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const { writeAsync, isLoading, isMining } = useScaffoldContractWrite({
contractName: "YourContract",
functionName: "setGreeting",
args: ["The value to set"],
// For payable functions, expressed in ETH
value: "0.01",
// For payable functions
value: parseEther("0.1"),
// The number of block confirmations to wait for before considering transaction to be confirmed (default : 1).
blockConfirmations: 1,
// The callback function to execute when the transaction is confirmed.
Expand All @@ -24,10 +24,18 @@ const { writeAsync, isLoading, isMining } = useScaffoldContractWrite({

To send the transaction, you can call the `writeAsync` function returned by the hook. Here's an example usage:

```ts
```tsx
<button className="btn btn-primary" onClick={() => writeAsync()}>
Send TX
</button>
```

This example sends a transaction to the `YourContract` smart contract to call the `setGreeting` function with the arguments passed in `args`. The `writeAsync` function sends the transaction to the smart contract, and the `isLoading` and `isMining` properties indicate whether the transaction is currently being processed by the network.

It is also possible to pass arguments imperatively to the `writeAsync` function:

```tsx
<button className="btn btn-primary" onClick={() => writeAsync({ args: ["Dynamic value"], value: parseEther("0.2") })}>
Send TX
</button>
```