Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added buildUserOp example to simulate a user op #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/Account/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ const { transactionHash, userOperationReceipt } = await waitForTxHash();

### buildUserOp( )

This method is used for configuring and setting up properties of the partial `userOp` object. It converts an individual transaction or batch of transactions into a partial user operation populating fields such as initCode, sender, nonce, maxFeePerGas, maxPriorityFeePerGas, callGasLimit, verificationGasLimit and preVerificationGas (as this step also involves estimating gas for the userOp internally)
This method is used for configuring and setting up properties of the partial `userOp` object. It converts an individual transaction or batch of transactions into a partial user operation populating fields such as initCode, sender, nonce, maxFeePerGas, maxPriorityFeePerGas, callGasLimit, verificationGasLimit and preVerificationGas (as this step also involves estimating gas for the userOp internally and simulating both validation and execution of the user op)

**Usage**

Expand Down Expand Up @@ -525,6 +525,10 @@ const tx1 = {
const userOp = await smartAccount.buildUserOp([tx1]);
```

:::note
buildUserOp() also simulates the validation and the execution of the user operation, this method can be used to check if a user operation will be successfull or not
:::

**Parameters**

- transactions (`Transaction[]`, required): The required argument is an array of transactions which will be executed in provided order. You can pass multiple transactions into a userOp if you would like to batch them together into one transaction.
Expand Down
42 changes: 42 additions & 0 deletions docs/tutorials/utils/simulateUserOp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
sidebar_label: "Simulate User Op"
sidebar_position: 3
title: "Simulate a User Op with buildUserOp()"
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

### Overview

This tutorial provides insights into how to simulate a user operation using the buildUserOp() method.


```typescript
const account = privateKeyToAccount("");

const signer = createWalletClient({
account,
chain: polygonAmoy,
transport: http(),
})

const smartAccount = await createSmartAccountClient({
signer,
bundlerUrl, // from Biconomy dashboard
paymasterUrl, // from Biconomy dashboard
});

const encodedCall = encodeFunctionData({
abi: parseAbi(["function safeMint(address _to)"]),
functionName: "safeMint",
args: [recipient]
})
const transaction = {
to: nftAddress,
data: encodedCall
}

// will throw an error if something is wrong with the transaction
await smartAccount.buildUserOp([transaction]);
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved
```
6 changes: 5 additions & 1 deletion versioned_docs/version-3.0/account/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const index = smartAccount.index;

### buildUserOp( )

This method is used for configuring and setting up properties of the partial `userOp` object. It converts an individual transaction or batch of transactions into a partial user operation populating fields such as initCode, sender, nonce, maxFeePerGas, maxPriorityFeePerGas, callGasLimit, verificationGasLimit and preVerificationGas (as This step also involves estimating gas for the userOp internally)
This method is used for configuring and setting up properties of the partial `userOp` object. It converts an individual transaction or batch of transactions into a partial user operation populating fields such as initCode, sender, nonce, maxFeePerGas, maxPriorityFeePerGas, callGasLimit, verificationGasLimit and preVerificationGas (as this step also involves estimating gas for the userOp internally and simulating both validation and execution of the user op)

**Usage**

Expand Down Expand Up @@ -133,6 +133,10 @@ const tx1 = {
const userOp = await smartAccount.buildUserOp([tx1]);
```

:::note
buildUserOp() also simulates the validation and the execution of the user operation, this method can be used to check if a user operation will be successfull or not
:::

**Parameters**

- transactions (`Transaction[]`, required): The required argument is an array of transactions which will be executed in provided order. You can pass multiple transactions into a userOp if you would like to batch them together into one transaction.
Expand Down