
Link
Batch transactions
Batch multiple transactions into a single on-chain transaction

Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Batch multiple transactions into a single on-chain transaction

import { useWalletKitLink } from "@walletkit/react-link";
import { parseUnits } from "viem";
export function App() {
const walletKit = useWalletKitLink();
const [hash, setHash] = useState("");
const sendTransaction = async () => {
const hash = await walletKit.signAndSendTransactions([
{
abi: erc20ABI,
address: USDC_ADDRESS,
functionName: "approve",
args: [
"0x000000000000000000000000000000000000dead",
parseUnits("5", 6),
],
},
{
abi: erc20ABI,
address: USDC_ADDRESS,
functionName: "transfer",
args: [
"0x000000000000000000000000000000000000dead",
parseUnits("5", 6),
],
},
]);
setHash(hash);
};
return (
<div>
<button onClick={() => sendTransaction()}>Send Transaction</button>
{hash ? <div>Transaction: {hash}</div> : null}
</div>
);
}
import { useBatchWriteContract } from "@walletkit/react-link";
function App() {
const [hash, setHash] = useState("");
const { batchWriteContractAsync } = useBatchWriteContract([
{
abi: erc20ABI,
address: USDC_ADDRESS,
functionName: "approve",
args: ["0x000000000000000000000000000000000000dead", parseUnits("5", 6)],
},
{
abi: erc20ABI,
address: USDC_ADDRESS,
functionName: "transfer",
args: ["0x000000000000000000000000000000000000dead", parseUnits("5", 6)],
},
]);
const handleSendTransaction = async () => {
const hash = await batchWriteContractAsync();
setHash(hash);
};
return (
<div>
<button onClick={handleSendTransaction}>Send Transaction</button>
{hash ? <div>Transaction: {hash}</div> : null}
</div>
);
}