File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
react/core/hooks/contract Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " thirdweb " : minor
3
+ ---
4
+
5
+ Export ` useSendBatchTransaction() ` for smart accounts
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ export {
53
53
// contract related
54
54
export { useReadContract } from "../react/core/hooks/contract/useReadContract.js" ;
55
55
export { useSendTransaction } from "../react/core/hooks/contract/useSendTransaction.js" ;
56
+ export { useSendBatchTransaction } from "../react/core/hooks/contract/useSendBatchTransaction.js" ;
56
57
export { useSendAndConfirmTransaction } from "../react/core/hooks/contract/useSendAndConfirmTransaction.js" ;
57
58
export { useEstimateGas } from "../react/core/hooks/contract/useEstimateGas.js" ;
58
59
export { useEstimateGasCost } from "../react/core/hooks/contract/useEstimateGasCost.js" ;
Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ export {
103
103
type SendTransactionOptions ,
104
104
} from "../transaction/actions/send-transaction.js" ;
105
105
export { sendAndConfirmTransaction } from "../transaction/actions/send-and-confirm-transaction.js" ;
106
+ export {
107
+ sendBatchTransaction ,
108
+ type SendBatchTransactionOptions ,
109
+ } from "../transaction/actions/send-batch-transaction.js" ;
106
110
export {
107
111
simulateTransaction ,
108
112
type SimulateOptions ,
Original file line number Diff line number Diff line change
1
+ import { type UseMutationResult , useMutation } from "@tanstack/react-query" ;
2
+ import { sendBatchTransaction } from "../../../../exports/transaction.js" ;
3
+ import type { WaitForReceiptOptions } from "../../../../transaction/actions/wait-for-tx-receipt.js" ;
4
+ import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js" ;
5
+ import { useActiveAccount } from "../wallets/wallet-hooks.js" ;
6
+
7
+ /**
8
+ * A hook to send a transaction.
9
+ * @returns A mutation object to send a transaction.
10
+ * @example
11
+ * ```jsx
12
+ * import { useSendBatchTransaction } from "thirdweb/react";
13
+ * const { mutate: sendBatch, data: transactionResult } = useSendBatchTransaction();
14
+ *
15
+ * // later
16
+ * sendBatch([tx1, tx2]);
17
+ * ```
18
+ * @transaction
19
+ */
20
+ export function useSendBatchTransaction ( ) : UseMutationResult <
21
+ WaitForReceiptOptions ,
22
+ Error ,
23
+ PreparedTransaction [ ]
24
+ > {
25
+ const account = useActiveAccount ( ) ;
26
+
27
+ return useMutation ( {
28
+ mutationFn : async ( transactions ) => {
29
+ if ( ! account ) {
30
+ throw new Error ( "No active account" ) ;
31
+ }
32
+ return await sendBatchTransaction ( {
33
+ transactions,
34
+ account,
35
+ } ) ;
36
+ } ,
37
+ } ) ;
38
+ }
You can’t perform that action at this time.
0 commit comments