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

added optional chainId to hooks #108

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions docs/hooks/useDeployedContractInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ sidebar_position: 5
Use this hook to fetch details about a deployed smart contract, including the ABI and address.

```ts
const { data: deployedContractData } = useDeployedContractInfo(contractName);
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.

## Parameters
## Configuration

| Parameter | Type | Description |
| :--------------- | :------- | :-------------------- |
| **contractName** | `string` | Name of the contract. |
| 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`](/deploying/deploy-nextjs-app#--targetnetworks) |

### Return Value

Expand Down
10 changes: 6 additions & 4 deletions docs/hooks/useScaffoldContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useWalletClient } from "wagmi";
const { data: walletClient } = useWalletClient();
const { data: yourContract } = useScaffoldContract({
contractName: "YourContract",
chainId: 31337,
walletClient,
});
const setGreeting = async () => {
Expand All @@ -32,10 +33,11 @@ This example uses the `useScaffoldContract` hook to obtain a contract instance f

## Configuration

| Parameter | Type | Description |
| :-------------------------- | :----------------------------------------------------------------- | :---------------------------------------------------------------------------- |
| **contractName** | `string` | Name of the contract. |
| **walletClient** (optional) | [`WalletClient`](https://wagmi.sh/react/api/hooks/useWalletClient) | Wallet client must be passed in order to call `write` methods of the contract |
| Parameter | Type | Description |
| :-------------------------- | :----------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
| **contractName** | `string` | Name of the contract. |
| **walletClient** (optional) | [`WalletClient`](https://wagmi.sh/react/api/hooks/useWalletClient) | Wallet client must be passed in order to call `write` methods of the contract |
| **chainId** (optional) | `string` | Id of the chain the contract lives on. Defaults to [`targetNetworks[0].id`](/deploying/deploy-nextjs-app#--targetnetworks) |

## Return Value

Expand Down
1 change: 1 addition & 0 deletions docs/hooks/useScaffoldEventHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This example retrieves the historical event logs for the `GreetingChange` event
| **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`](/deploying/deploy-nextjs-app#--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`](/deploying/deploy-nextjs-app#--targetnetworks) |

## Return Values

Expand Down
13 changes: 7 additions & 6 deletions docs/hooks/useScaffoldReadContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ This example retrieves the data returned by the `userGreetingCounter` function o

## 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`) |
| 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`](/deploying/deploy-nextjs-app#--targetnetworks) |

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

Expand Down
11 changes: 6 additions & 5 deletions docs/hooks/useScaffoldWatchContractEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ Due to shortcomings of some RPC providers, this hook may or may not fire events

## 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`](/deploying/deploy-nextjs-app#--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. |
| 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`](/deploying/deploy-nextjs-app#--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`](/deploying/deploy-nextjs-app#--targetnetworks) |

:::note

Expand Down
17 changes: 9 additions & 8 deletions docs/hooks/useScaffoldWriteContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 2
Use this hook to send a transaction to your smart contract to write data or perform an action.

```ts
const { writeContractAsync: writeYourContractAsync } = useScaffoldWriteContract("YourContract");
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).
Expand Down Expand Up @@ -39,13 +39,14 @@ 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). |
| 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) |

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

Expand Down
Loading