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

mention about config object for useScaffoldWriteContract hook #109

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from 2 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
25 changes: 16 additions & 9 deletions docs/hooks/useScaffoldWriteContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ Use this hook to send a transaction to your smart contract to write data or perf
const { writeContractAsync: writeYourContractAsync } = useScaffoldWriteContract({ contractName: "YourContract" });
```

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).
Following configuration can be passed to hook:
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved

## Configuration

| Parameter | Type | Description |
| :------------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------- |
| **contractName** | `string` | Name of the contract to read. |
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to [`targetNetworks[0].id`](/deploying/deploy-nextjs-app#--targetnetworks) |
| **wagmiParamsObject** (optional) | `object` | wagmi's `useWriteContract` hook [parameters object](https://wagmi.sh/react/api/hooks/useWriteContract#parameters) |
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved

To send the transaction, you can call the `writeContractAsync` function returned by the hook (which we instance as `writeYourContractAsync`). Here's an example usage:

Expand Down Expand Up @@ -39,14 +47,13 @@ Below is the configuration for `writeContractAsync` function:

## Configuration

| Parameter | Type | Description |
| :--------------------------------- | :---------- | :------------------------------------------------------------------------------------------------------------------------- |
| **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. |
| **value** (optional) | `bigint` | Amount of ETH to send with the transaction (for payable functions only). |
| **onBlockConfirmation** (optional) | `function` | Callback function to execute when the transaction is confirmed. |
| **blockConfirmations** (optional) | `number` | Number of block confirmations to wait for before considering transaction to be confirmed (default : 1). |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to [`targetNetworks[0].id`](/deploying/deploy-nextjs-app#--targetnetworks) |
| Parameter | Type | Description |
| :--------------------------------- | :---------- | :------------------------------------------------------------------------------------------------------------------- |
| **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. |
| **value** (optional) | `bigint` | Amount of ETH to send with the transaction (for payable functions only). |
| **onBlockConfirmation** (optional) | `function` | Callback function to execute when the transaction is confirmed. |
| **blockConfirmations** (optional) | `number` | Number of block confirmations to wait for before considering transaction to be confirmed (default : 1). |

You can also pass other arguments accepted by [writeContractAsync from wagmi](https://wagmi.sh/react/api/hooks/useWriteContract#mutate-async).

Expand Down
Loading