diff --git a/docs/hooks/useScaffoldContract.md b/docs/hooks/useScaffoldContract.md index 1848794..33c4397 100644 --- a/docs/hooks/useScaffoldContract.md +++ b/docs/hooks/useScaffoldContract.md @@ -15,12 +15,12 @@ const { data: yourContract } = useScaffoldContract({ await yourContract?.read.greeting(); // Used to write to a contract and can be called in any function -import { useWalletClient } from "wagmi"; +import { useAccount } from "@starknet-react/core"; -const { data: walletClient } = useWalletClient(); +const { account } = useAccount(); const { data: yourContract } = useScaffoldContract({ contractName: "YourContract", - walletClient, + account, }); const setGreeting = async () => { // Call the method in any function @@ -32,13 +32,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. | ## Return Value -- `data` : Object representing viem's [contract instance](https://viem.sh/docs/contract/getContract.html#return-value). Which can be used to call `read` and `write` of the contract. - +- `data`: An instance of the contract, which can be used to call `read` and `write` methods of the contract. - `isLoading` : Boolean indicating if the contract is being loaded. diff --git a/docs/hooks/useScaffoldMultiWriteContract.md b/docs/hooks/useScaffoldMultiWriteContract.md new file mode 100644 index 0000000..0b42a19 --- /dev/null +++ b/docs/hooks/useScaffoldMultiWriteContract.md @@ -0,0 +1,68 @@ +--- +sidebar_position: 2 +--- + +# useScaffoldMultiWriteContract + +Use this hook to write to state-changing functions of your smart contract. + +```ts +const { writeAsync } = useScaffoldMultiWriteContract({ + calls: [ + { + contractName: "YourContract1", + functionName: "setGreeting", + args: ["Hello"], + }, + { + contractName: "YourContract2", + functionName: "setCounter", + args: [42], + }, + ], +}); +``` + +This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The `writeAsync` function sends the transactions to the smart contracts. + +## Usage Example + +```tsx + +``` + +This example demonstrates how to use the `writeAsync`function to send multiple transactions to the specified smart contracts, calling the functions with the arguments passed in calls. + +## Configuration + +| Parameter | Type | Description | +| :--------------------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------- | +| **calls** | `Array` | Array of configuration objects for the contract calls. Each object should contain `contractName`, `functionName`, and `args`. | +| **options** (optional) | `InvocationsDetails` | Additional options for the transactions. | + +## Call Object Configuration + +| Parameter | Type | Description | +| :------------------ | :---------- | :--------------------------------------------------------------------------------------------------------------- | +| **contractName** | `string` | Name of the contract to write to. | +| **functionName** | `string` | Name of the function to call. | +| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. | + +You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite). + +## Return Values + +- `writeContractAsync` function sends the transaction to the smart contract. +- `isMining` property indicates whether the transaction is currently being mined. +- The extended object includes properties inherited from the useContractWrite hook from starknet-react. You can check the [useContractWrite return values](https://starknet-react.com/hooks/mutation/usecontractwrite) for the types. diff --git a/docs/hooks/useScaffoldReadContract.md b/docs/hooks/useScaffoldReadContract.md index caac808..6ca44b8 100644 --- a/docs/hooks/useScaffoldReadContract.md +++ b/docs/hooks/useScaffoldReadContract.md @@ -27,9 +27,9 @@ This example retrieves the data returned by the `userGreetingCounter` function o | **watch** (optional) | `boolean` | Watches and refreshes data on new blocks. (default : `true`) | | Other arguments | `various` | You can pass other arguments accepted by the useContractRead hook from @starknet-react/core. | -You can also pass other arguments accepted by [useReadContract wagmi hook](https://wagmi.sh/react/api/hooks/useReadContract#parameters). +You can also pass other arguments accepted by [useContractRead from Starknet-react](https://starknet-react.com/hooks/query/usecontractread). ## Return Values - The retrieved data is stored in the `data` property of the returned object. -- The extended object includes properties inherited from the useContractRead hook of starknet-react. You can check the [useReadContract return values](https://starknet-react.com/hooks/query/usecontractread) documentation for the types. +- The extended object includes properties inherited from the useContractRead hook of starknet-react. You can check the [useContractRead return values](https://starknet-react.com/hooks/query/usecontractread) documentation for the types. diff --git a/docs/hooks/useScaffoldWatchContractEvent.md b/docs/hooks/useScaffoldWatchContractEvent.md index 849bb1b..26a5e51 100644 --- a/docs/hooks/useScaffoldWatchContractEvent.md +++ b/docs/hooks/useScaffoldWatchContractEvent.md @@ -1,5 +1,5 @@ --- -sidebar_position: 3 +sidebar_position: 7 --- # useScaffoldWatchContractEvent (Coming soon) diff --git a/docs/hooks/useScaffoldWriteContract.md b/docs/hooks/useScaffoldWriteContract.md index 6bb9d4b..ec25052 100644 --- a/docs/hooks/useScaffoldWriteContract.md +++ b/docs/hooks/useScaffoldWriteContract.md @@ -1,68 +1,55 @@ --- -sidebar_position: 4 +sidebar_position: 3 --- # useScaffoldWriteContract -Use this hook to write to state-changing functions of your smart contract. +Use this hook to write to your smart contract by calling state-mutating functions. ```ts const { writeAsync } = useScaffoldWriteContract({ - calls: [ - { - contractName: "YourContract1", - functionName: "setGreeting", - args: ["Hello"], - }, - { - contractName: "YourContract2", - functionName: "setCounter", - args: [42], - }, - ], + contractName: "YourContract", + functionName: "updateGreeting", + args: ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "Hello, world!"], }); ``` -This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The writeAsync function sends the transactions to the smart contracts. +This example calls the updateGreeting function of the YourContract smart contract. ## Usage Example ```tsx - +const { writeAsync } = useScaffoldWriteContract({ + contractName: "YourContract", + functionName: "updateGreeting", + args: ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "Hello, world!"], + options: { gas: 100000 }, +}); + +const handleUpdateGreeting = async () => { + try { + const result = await writeAsync(); + console.log("Transaction successful:", result); + } catch (error) { + console.error("Transaction failed:", error); + } +}; ``` -This example demonstrates how to use the writeAsync function to send multiple transactions to the specified smart contracts, calling the functions with the arguments passed in calls. +In this example, the updateGreeting function of the YourContract is called with the specified arguments. The transaction is sent using the `writeAsync` method, which handles the logic for sending the transaction and returns a promise ## Configuration -| Parameter | Type | Description | -| :--------------------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------- | -| **calls** | `Array` | Array of configuration objects for the contract calls. Each object should contain `contractName`, `functionName`, and `args`. | -| **options** (optional) | `InvocationsDetails` | Additional options for the transactions. | - -## Call Object Configuration - -| Parameter | Type | Description | -| :------------------ | :---------- | :--------------------------------------------------------------------------------------------------------------- | -| **contractName** | `string` | Name of the contract to write to. | -| **functionName** | `string` | Name of the function to call. | -| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. | +| Parameter | Type | Description | +| :-------------------- | :---------- | :--------------------------------------------------------------------------------------------------------------- | +| **contractName** | `string` | Name of the contract to write to. | +| **functionName** | `string` | Name of the function to call. | +| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. | +| **option** (optional) | `object` | Additional options for the transaction, such as gas and value. | -You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite). +You can also pass other arguments accepted by [useContractWrite from Starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite). ## Return Values -- `writeContractAsync` function sends the transaction to the smart contract. -- `isMining` property indicates whether the transaction is currently being mined. -- The extended object includes properties inherited from the useContractWrite hook from starknet-react. You can check the [usecontractwrite return values](https://starknet-react.com/hooks/mutation/usecontractwrite) for the types. +- The writeAsync method is used to send the write transaction. It returns a promise that resolves when the transaction is confirmed. +- The extended object includes properties inherited from the useContractWrite hook of starknet-react. You can check the [useContractWrite return values](https://starknet-react.com/hooks/mutation/usecontractwrite) documentation for the types.