Skip to content

Commit

Permalink
Merge pull request #120 from bcnmy/fix/batchingtransactions
Browse files Browse the repository at this point in the history
Update batchingTransactions.md
  • Loading branch information
Rahat-ch committed Nov 30, 2023
2 parents 7cfc2a0 + 370a8f0 commit 15cad99
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions docs/tutorials/nodejs/batchingTransactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sidebar_position: 4

# Batching Multiple Transactions

In this guide, we will edit the functionality in the previous section to not only mint a gassless transaction but to showcase batching transactions by minting multiple transactions together.
In this guide, we will edit the functionality in the previous section to not only mint a gasless transaction but to showcase batching transactions by minting multiple transactions together.

<details>
<summary> Click to view code from previous section </summary>
Expand Down Expand Up @@ -126,8 +126,10 @@ mintNFT();
Our Focus for this edit will be on the following section of the mintNFT function:

```typescript
const smartAccount = await createAccount();
const address = await smartAccount.getAccountAddress();

const nftInterface = new ethers.utils.Interface([
const nftInterface = new ethers.utils.Interface([
"function safeMint(address _to)",
]);

Expand All @@ -148,7 +150,7 @@ const nftInterface = new ethers.utils.Interface([

```

We start constructing our transaction here and pass the transaction to an array within the Smart Accounts `buildUserOp` method. The quickest edit we can do here is simply pass the transaction multiple times:
We begin by constructing a transaction and then pass it multiple times to the `buildUserOp` method of Smart Accounts. For simplicity, we'll just copy the same `transaction` object multiple times in the array.

```typescript

Expand All @@ -160,9 +162,8 @@ let partialUserOp = await smartAccount.buildUserOp([transaction, transaction], {

```

Passing the transaction twice in the Array will allow you to mint multiple NFTs in one transaction. This is useful for use cases such as using NFT's as a ticketing system and needing to mint multiple tickets, or creating one click experiences in defi by passing multiple types of transactions into the array.

Try running the script yourself with this edit and you will notice multiple mints in the transaction details, allowing you to save gas in cases where users need to conduct multiple transactions.
By duplicating the `transaction` in the array, we enable the minting of several NFTs in a single operation. This approach is ideal for scenarios like **issuing multiple tickets via NFTs** or **streamlining DeFi interactions with one-click multi-transactions**.

In the next section we'll take a look at converting our script from being a gasless transaction to now instead paying for gas using an ERC20 token.
By making this change to your script, you can mint multiple NFTs in a single transaction, which saves on gas fees for multiple actions.

Next, we'll transition our script from **gasless transactions** to **utilizing ERC20 tokens for gas payments**.

0 comments on commit 15cad99

Please sign in to comment.