|
| 1 | +--- |
| 2 | +sidebar_position: 4 |
| 3 | +--- |
| 4 | + |
| 5 | +# useScaffoldMultiContractWrite |
| 6 | + |
| 7 | +Use this hook to send multiple transactions to your smart contracts to write data or perform actions. |
| 8 | + |
| 9 | +```ts |
| 10 | +const { writeAsync: writeMultipleContractsAsync } = useScaffoldMultiContractWrite({ |
| 11 | + calls: [ |
| 12 | + { |
| 13 | + contractName: "YourContract1", |
| 14 | + functionName: "setGreeting", |
| 15 | + args: ["Hello"], |
| 16 | + }, |
| 17 | + { |
| 18 | + contractName: "YourContract2", |
| 19 | + functionName: "setCounter", |
| 20 | + args: [42], |
| 21 | + }, |
| 22 | + ], |
| 23 | +}); |
| 24 | +``` |
| 25 | + |
| 26 | +This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The writeAsync function (writeMultipleContractsAsync instance) sends the transactions to the smart contracts. |
| 27 | + |
| 28 | +## Usage Example |
| 29 | + |
| 30 | +```tsx |
| 31 | +<button |
| 32 | + className="btn btn-primary" |
| 33 | + onClick={async () => { |
| 34 | + try { |
| 35 | + await writeMultipleContractsAsync(); |
| 36 | + } catch (e) { |
| 37 | + console.error("Error sending transactions:", e); |
| 38 | + } |
| 39 | + }} |
| 40 | +> |
| 41 | + Send Transactions |
| 42 | +</button> |
| 43 | +``` |
| 44 | + |
| 45 | +This example sends multiple transactions to the specified smart contracts to call the functions with the arguments passed in calls. The writeAsync function (writeMultipleContractsAsync instance) sends the transactions to the smart contracts. |
| 46 | + |
| 47 | +## Configuration |
| 48 | + |
| 49 | +| Parameter | Type | Description | |
| 50 | +| :--------------------- | :------------------------------------------------------------ | :---------------------------------------------------------------------------------- | |
| 51 | +| **calls** | `Array<UseScaffoldWriteConfig<TContractName, TFunctionName>>` | An array of calls, each containing the contract name, function name, and arguments. | |
| 52 | +| **options** (optional) | `InvocationsDetails` | Additional options for the transactions. | |
| 53 | + |
| 54 | +## Call Object Configuration |
| 55 | + |
| 56 | +| Parameter | Type | Description | |
| 57 | +| :------------------ | :---------- | :--------------------------------------------------------------------------------------------------------------- | |
| 58 | +| **contractName** | `string` | Name of the contract to write to. | |
| 59 | +| **functionName** | `string` | Name of the function to call. | |
| 60 | +| **args** (optional) | `unknown[]` | Array of arguments to pass to the function (if any). Types are inferred from the contract's function parameters. | |
| 61 | + |
| 62 | +You can also pass other arguments accepted by [writeContractAsync from starknet-react](https://starknet-react.com/hooks/mutation/usecontractwrite). |
| 63 | + |
| 64 | +## Return Values |
| 65 | + |
| 66 | +- `writeContractAsync` function sends the transaction to the smart contract. |
| 67 | +- `isMining` property indicates whether the transaction is currently being mined. |
| 68 | +- The extended object includes properties inherited from the useContractWrite hook from starknet-react. You can check the [usecontractwrite return values](https://wagmi.sh/react/api/hooks/useWriteContract#return-type) for the types. |
0 commit comments