diff --git a/docs/Account/methods.md b/docs/Account/methods.md index 632a3ad0..a3b9080e 100644 --- a/docs/Account/methods.md +++ b/docs/Account/methods.md @@ -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** @@ -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. diff --git a/docs/tutorials/utils/simulateUserOp.md b/docs/tutorials/utils/simulateUserOp.md new file mode 100644 index 00000000..66a52116 --- /dev/null +++ b/docs/tutorials/utils/simulateUserOp.md @@ -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]); +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/account/methods.md b/versioned_docs/version-3.0/account/methods.md index c94013be..69ca34f2 100644 --- a/versioned_docs/version-3.0/account/methods.md +++ b/versioned_docs/version-3.0/account/methods.md @@ -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** @@ -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.