EIP5792.useSendAndConfirmCalls

A hook to send EIP-5792 calls to a wallet. This hook works with all Thirdweb wallets (in-app and smart) and certain injected wallets that already support EIP-5792. Transactions will be batched and sponsored when those capabilities are supported, otherwise they will be sent as individual transactions.

When calls are sent, all contracts that are interacted with will have their corresponding reads revalidated via React Query.

This hook is dependent on the wallet's support for EIP-5792 and could fail. The mutation function will use your currently connected wallet by default, but you can pass it a specific wallet to use if you'd like.

Example

import { useSendCalls } from "thirdweb/react";
const sendTx1 = approve({
contract: USDT_CONTRACT,
amount: 100,
spender: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
});
const sendTx2 = approve({
contract: USDT_CONTRACT,
amount: 100,
spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
});
const { mutate: sendCalls, data: result } = useSendAndConfirmCalls();
await sendCalls({
client,
calls: [sendTx1, sendTx2],
});
console.log(
"Transaction hash:",
result.receipts?.[0]?.transactionHash,
);

Sponsor transactions with a paymaster:

const { mutate: sendAndConfirmCalls, data: id } =
useSendAndConfirmCalls();
const result = await sendAndConfirmCalls({
client,
calls: [sendTx1, sendTx2],
capabilities: {
paymasterService: {
url: `https://${CHAIN.id}.bundler.thirdweb.com/${client.clientId}`,
},
},
});
console.log(
"Transaction hash:",
result.receipts?.[0]?.transactionHash,
);

We recommend proxying any paymaster calls via an API route you setup and control.

function useSendAndConfirmCalls(args?: {
maxBlocksWaitTime?: number;
}): UseMutationResult<
{
atomic: boolean;
chainId: number;
id: string;
receipts?: Array<
WalletCallReceipt<bigint, "success" | "reverted">
>;
status: undefined | "pending" | "success" | "failure";
statusCode: number;
version: string;
},
Error,
Omit<
{
atomicRequired?: boolean;
calls: Array<PreparedSendCall<[], AbiFunction>>;
capabilities?: WalletCapabilities;
chain?: Readonly<ChainOptions & { rpc: string }>;
version?: string;
wallet: Wallet<WalletId>;
},
"chain" | "wallet"
> & { wallet?: Wallet }
>;

Parameters

Type

let args: { maxBlocksWaitTime?: number };

Returns

let returnType: UseMutationResult<
{
atomic: boolean;
chainId: number;
id: string;
receipts?: Array<
WalletCallReceipt<bigint, "success" | "reverted">
>;
status: undefined | "pending" | "success" | "failure";
statusCode: number;
version: string;
},
Error,
Omit<
{
atomicRequired?: boolean;
calls: Array<PreparedSendCall<[], AbiFunction>>;
capabilities?: WalletCapabilities;
chain?: Readonly<ChainOptions & { rpc: string }>;
version?: string;
wallet: Wallet<WalletId>;
},
"chain" | "wallet"
> & { wallet?: Wallet }
>;

A React Query mutation object to interact with sendAndConfirmCalls