Skip to content

Commit 14cecc9

Browse files
feat: expose useSendBatchTransaction for smart accounts (#2711)
Signed-off-by: Jonas Daniels <jonas.daniels@outlook.com> Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent 30e6385 commit 14cecc9

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

.changeset/tidy-colts-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Export `useSendBatchTransaction()` for smart accounts

packages/thirdweb/src/exports/react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export {
5353
// contract related
5454
export { useReadContract } from "../react/core/hooks/contract/useReadContract.js";
5555
export { useSendTransaction } from "../react/core/hooks/contract/useSendTransaction.js";
56+
export { useSendBatchTransaction } from "../react/core/hooks/contract/useSendBatchTransaction.js";
5657
export { useSendAndConfirmTransaction } from "../react/core/hooks/contract/useSendAndConfirmTransaction.js";
5758
export { useEstimateGas } from "../react/core/hooks/contract/useEstimateGas.js";
5859
export { useEstimateGasCost } from "../react/core/hooks/contract/useEstimateGasCost.js";

packages/thirdweb/src/exports/thirdweb.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export {
103103
type SendTransactionOptions,
104104
} from "../transaction/actions/send-transaction.js";
105105
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";
106110
export {
107111
simulateTransaction,
108112
type SimulateOptions,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)