useSendCalls

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 bundled 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 mutatuon 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: bundleId } = useSendCalls({
client,
});
await sendCalls({
wallet,
client,
calls: [sendTx1, sendTx2],
});

Await the bundle's full confirmation:

const { mutate: sendCalls, data: bundleId } = useSendCalls({
client,
waitForResult: true,
});
await sendCalls({
wallet,
client,
calls: [sendTx1, sendTx2],
});

Sponsor transactions with a paymaster:

const { mutate: sendCalls, data: bundleId } = useSendCalls();
await sendCalls({
client,
calls: [sendTx1, sendTx2],
capabilities: {
paymasterService: {
url: `https://${CHAIN.id}.bundler.thirdweb.com/${client.clientId}`,
},
},
});

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

function useSendCalls(__namedParameters: {
client: ThirdwebClient;
waitForResult?: boolean;
}): UseMutationResult<
Error,
Omit<SendCallsOptions, "chain" | "wallet"> & { wallet?: Wallet }
>;

Parameters

Type

let __namedParameters: {
client: ThirdwebClient;
waitForResult?: boolean;
};

Returns

let returnType: UseMutationResult<
Error,
Omit<SendCallsOptions, "chain" | "wallet"> & { wallet?: Wallet }
>;

A React Query mutatuon object to interact with sendCalls