This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aacb00
commit 3b05fc1
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/app/connect/account-abstraction/batching-transactions/page.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { createMetadata } from "@doc"; | ||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; | ||
|
||
# Batching transactions | ||
|
||
export const metadata = createMetadata({ | ||
image: { | ||
title: "Batching transactions", | ||
icon: "wallets", | ||
}, | ||
title: "Batching transactions | thirdweb", | ||
description: "How to batch transactions with smart accounts", | ||
}); | ||
|
||
Batching transactions allows sending multiple transactions in a single user operation. This can be useful to save on fees, reduce number of user confimations or to ensure that multiple transactions are executed atomically. | ||
|
||
A typical example is to do an approval and a transfer in a single userOperation. This way, the transfer will only happen if the approval is successful. | ||
|
||
<Tabs defaultValue="react"> | ||
|
||
<TabsList> | ||
<TabsTrigger value="react">React</TabsTrigger> | ||
<TabsTrigger value="typescript">TypeScript</TabsTrigger> | ||
</TabsList> | ||
|
||
<TabsContent value="react"> | ||
|
||
```tsx | ||
import { useActiveAccount, useSendBatchTransaction } from "thirdweb/react"; | ||
import { approve, transferFrom } from "thirdweb/extensions/erc20"; | ||
|
||
const smartAccount = useActiveAccount(); | ||
const { mutate: sendBatchTransaction } = useSendBatchTransaction(); | ||
|
||
const approveAndTransfer = async () => { | ||
const transactions = [ | ||
approve({ | ||
contract, | ||
spender: "0x...", | ||
value: 100, | ||
}), | ||
transferFrom({ | ||
contract, | ||
from: "0x...", | ||
to: "0x...", | ||
amount: 100, | ||
}), | ||
]; | ||
await sendBatchTransaction(transactions); | ||
}; | ||
``` | ||
|
||
</TabsContent> | ||
|
||
<TabsContent value="typescript"> | ||
|
||
```tsx | ||
import { smartWallet } from "thirdweb/wallets"; | ||
import { sendBatchTransaction } from "thirdweb"; | ||
import { approve, transferFrom } from "thirdweb/extensions/erc20"; | ||
|
||
const smartWallet = new smartWallet(config); | ||
const smartAccount = await smartWallet.connect({ | ||
client, | ||
personalAccount, | ||
}); | ||
|
||
const transactions = [ | ||
approve({ | ||
contract, | ||
spender: "0x...", | ||
value: 100, | ||
}), | ||
transferFrom({ | ||
contract, | ||
from: "0x...", | ||
to: "0x...", | ||
amount: 100, | ||
}), | ||
]; | ||
|
||
await sendBatchTransaction({ | ||
transactions, | ||
account: smartAccount, | ||
}); | ||
``` | ||
|
||
</TabsContent> | ||
|
||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters