diff --git a/packages/accounts/README.md b/packages/accounts/README.md index dd7fa680dd..3e2ade1e64 100644 --- a/packages/accounts/README.md +++ b/packages/accounts/README.md @@ -36,7 +36,7 @@ If you are looking to add a new account type, please follow the following struct export const MyContractAbi = [] as const; // the as const is important so we can get correct typing from viem ``` -4. If you need to extend the [`SmartAccountProvider`](https://accountkit.alchemy.com/packages/aa-core/provider/introduction.html) class, add a file called `provider.ts` and add your implementation for `SmartAccountProvider`. +4. If you need to extend the [`SmartAccountProvider`](https://accountkit.alchemy.com/packages/aa-core/smart-account-client/introduction.html) class, add a file called `provider.ts` and add your implementation for `SmartAccountProvider`. - Ideally, your `Account` impl should _just_ work with the base provider provided by `aa-core`. - If not, consider generalizing the use case and updating SmartAccountProvider diff --git a/packages/core/src/client/smartAccountClient.ts b/packages/core/src/client/smartAccountClient.ts index 4600c46092..1b324eeb2b 100644 --- a/packages/core/src/client/smartAccountClient.ts +++ b/packages/core/src/client/smartAccountClient.ts @@ -146,12 +146,12 @@ export function createSmartAccountClientFromExisting< >( config: Omit< SmartAccountClientConfig, - "transport" + "transport" | "chain" > & { client: TClient } ): SmartAccountClient; export function createSmartAccountClientFromExisting( - config: Omit & { + config: Omit & { client: BundlerClient; } ): SmartAccountClient { diff --git a/site/.vitepress/sidebar/packages/aa-core.ts b/site/.vitepress/sidebar/packages/aa-core.ts index ccf62d2956..37a48e6341 100644 --- a/site/.vitepress/sidebar/packages/aa-core.ts +++ b/site/.vitepress/sidebar/packages/aa-core.ts @@ -10,18 +10,15 @@ export const aaCoreSidebar: DefaultTheme.SidebarItem = { link: "/", }, { - text: "Provider", + text: "Smart Account Client", + base: "/packages/aa-core/smart-account-client", + link: "/index", + }, + { + text: "Smart Account Actions", collapsed: true, - base: "/packages/aa-core/provider", + base: "/packages/aa-core/smart-account-client/actions", items: [ - { - text: "Introduction", - link: "/introduction", - }, - { - text: "constructor", - link: "/constructor", - }, { text: "sendUserOperation", link: "/sendUserOperation", @@ -86,49 +83,9 @@ export const aaCoreSidebar: DefaultTheme.SidebarItem = { text: "getAddress", link: "/getAddress", }, - { - text: "getEntryPointAddress", - link: "/getEntryPointAddress", - }, - { - text: "isConnected", - link: "/isConnected", - }, - { - text: "withPaymasterMiddleware", - link: "/withPaymasterMiddleware", - }, - { - text: "withGasEstimator", - link: "/withGasEstimator", - }, - { - text: "withFeeDataGetter", - link: "/withFeeDataGetter", - }, - { - text: "withCustomMiddleware", - link: "/withCustomMiddleware", - }, - { - text: "withUOSimulationMiddleware", - link: "/withUOSimulationMiddleware", - }, - { - text: "connect", - link: "/connect", - }, - { - text: "disconnect", - link: "/disconnect", - }, - { - text: "extend", - link: "/extend", - }, { text: "Types", - base: "/packages/aa-core/provider/types", + base: "/packages/aa-core/smart-account-client/types", collapsed: true, items: [ { diff --git a/site/getting-started.md b/site/getting-started.md deleted file mode 100644 index 858e282742..0000000000 --- a/site/getting-started.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: Getting Started Guide - - - meta - - name: description - content: Learn how to get started with Account Kit, a vertically integrated stack for building apps that support ERC-4337. - - - meta - - property: og:description - content: Learn how to get started with Account Kit, a vertically integrated stack for building apps that support ERC-4337. - - - meta - - name: twitter:title - content: Getting Started Guide - - - meta - - name: twitter:description - content: Learn how to get started with Account Kit, a vertically integrated stack for building apps that support ERC-4337. ---- - -# Getting Started - -This guide will help you get started with Account Kit by setting up your environment, creating a Light Account (a type of smart account implementation), and sending a User Operation from it. By the end of this guide, you'll have a basic understanding of how to use the SDK and where to look for more advanced use cases. - -## Install the Packages - -In your project directory, you'll need to install the required packages: - -::: code-group - -```bash [npm] -npm install @alchemy/aa-alchemy @alchemy/aa-accounts @alchemy/aa-core viem -``` - -```bash [yarn] -yarn add @alchemy/aa-alchemy @alchemy/aa-accounts @alchemy/aa-core viem -``` - -Note that we're installing [viem](https://viem.sh/) as well. Viem contains helpful abstractions and modules that may come in handy when using Account Kit. Additionally, many Account Kit modules leverage viem themselves. - -::: - -## A Simple Light Account Example - -Using the SDK, we'll deploy a Light Account and send a User Operation from it. The Light Account will be owned by an Externally Owned Account (EOA). Here's a demonstration: - -<<< @/snippets/light-account.ts - -This initializes a `provider` for your smart account which is then used to send user operations from it. It also logs the address of the deployed smart account. - -::: tip Note -Remember to: - -1. Replace `"0xYourEOAPrivateKey"` with your actual EOA private key. -2. Set `"ALCHEMY_API_KEY"` with your unique Alchemy API key. -3. Fund your smart account address with some SepoliaETH in order for the user operation to go through. This address is logged to the console when you run the script. -4. Adjust the `target` and `data` fields in the `sendUserOperation` function to match your requirements. - -::: - -## Dive Deeper - -In this guide we initialized `provider` with the `aa-alchemy` package however we could have done the same with the other packages of Account Kit as well. To learn more about the different packages and their use cases, check out the ["Packages Overview"](/overview/package-overview) page. - -## Next Steps - -To learn about the end-to-end process of integrating smart accounts in your applications check out the section on [smart accounts overview](/smart-accounts/overview.html) diff --git a/site/overview/faqs.md b/site/overview/faqs.md index e6f297abc7..337a4bf81e 100644 --- a/site/overview/faqs.md +++ b/site/overview/faqs.md @@ -64,9 +64,9 @@ If the `UserOperation` (meta-transaction for 4337 accounts) is correctly priced ::: details Answer This can happen when `UserOperation`s (UOs) become underpriced, frequently due to fee market movement between when gas and fees are estimations and when the UO is actually submitted. -You may experience this when calling the [`waitForUserOperationTransaction`](/packages/aa-core/provider/waitForUserOperationTransaction.html#waitForUserOperationTransaction) method. It may throw an error if it does not find the UO in a mined Transaction within its retry limits. +You may experience this when calling the [`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/waitForUserOperationTransaction.html#waitForUserOperationTransaction) method. It may throw an error if it does not find the UO in a mined Transaction within its retry limits. -You can mitigate this by defining a more flexible retry period when constructing a [`Provider`](/packages/aa-core/provider/constructor.html#constructor) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). If your UO continues to be delayed beyond a limit you are willing to wait, you can resubmit it using [`dropAndReplaceUserOperation`](/packages/aa-core/provider/dropAndReplaceUserOperation.html#dropandreplaceuseroperation). +You can mitigate this by defining a more flexible retry period when constructing a [`Provider`](/packages/aa-core/smart-account-client/createSmartAccountClient.html#constructor) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). If your UO continues to be delayed beyond a limit you are willing to wait, you can resubmit it using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/dropAndReplaceUserOperation.html#dropandreplaceuseroperation). ::: ### Are `UserOperation`s protected from MEV bots? @@ -86,7 +86,7 @@ Yes! Check out [this guide](/tutorials/sim-user-operation.html). ### How does gas estimation for 4337 smart contract accounts work? ::: details Answer -Our bundler estimates gas and submits `UserOperation`s (UOs) under the hood of the aa-sdk. Our gas estimations are just that, estimations that optimize for UOs landing on chain, and you may need to adjust gas limits based on your needs using [overrides](/packages/aa-core/provider/types/userOperationOverrides.html). +Our bundler estimates gas and submits `UserOperation`s (UOs) under the hood of the aa-sdk. Our gas estimations are just that, estimations that optimize for UOs landing on chain, and you may need to adjust gas limits based on your needs using [overrides](/packages/aa-core/smart-account-client/types/userOperationOverrides.html). Learn more about gas estimation and how it is implemented in our [Bundler](https://www.alchemy.com/blog/erc-4337-gas-estimation). @@ -142,7 +142,7 @@ Precheck failed errors are often related to gas and/or fees. Our Bundler follows These errors are often related to market movement between the time when gas and fees are estimated and the time when UOs are submitted to the bundler. This fluctuation in the market is especially variant on testnet. To ensure your UO is included in a block, we currently reject sending any UOs that are underpriced compared to the network rate . -To handle these errors, we recommend you use our [override fields](/packages/aa-core/provider/types/userOperationOverrides) to increase buffers on top of our estimates and implement retry mechanisms as needed. +To handle these errors, we recommend you use our [override fields](/packages/aa-core/smart-account-client/types/userOperationOverrides) to increase buffers on top of our estimates and implement retry mechanisms as needed. Our gas and fee estimations are just that, estimations, but we are always working to improve these estimates! ::: @@ -156,9 +156,9 @@ Currently our Bundler allows max 10M gas in aggregate between `preVerificationGa ### `waitForUserOperationTransaction` timeout ::: details Answer -[`waitForUserOperationTransaction`](/packages/aa-core/provider/waitForUserOperationTransaction) may throw this error if it does not find the mined User Operation within its retry limits. +[`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/waitForUserOperationTransaction) may throw this error if it does not find the mined User Operation within its retry limits. -You can mitigate this by defining a more flexible retry period when constructing a [`Provider`](/packages/aa-core/provider/constructor.html#constructor) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). +You can mitigate this by defining a more flexible retry period when constructing a [`Client`](/packages/aa-core/smart-account-client/createSmartAccountClient.html#usage) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). -If your `UserOperation` continues to be delayed beyond a limit you are willing to wait, you can resubmit the user operation using [`dropAndReplaceUserOperation`](/packages/aa-core/provider/dropAndReplaceUserOperation.html#dropandreplaceuseroperation). +If your `UserOperation` continues to be delayed beyond a limit you are willing to wait, you can resubmit the user operation using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/dropAndReplaceUserOperation.html#dropandreplaceuseroperation). ::: diff --git a/site/packages/aa-accounts/light-account/provider.md b/site/packages/aa-accounts/light-account/provider.md index 8b6ee19f68..c588f9025e 100644 --- a/site/packages/aa-accounts/light-account/provider.md +++ b/site/packages/aa-accounts/light-account/provider.md @@ -49,8 +49,8 @@ A Promise containing a new `SmartAccountProvider` connected to a Light Account. - `txRetryMulitplier: string | undefined` -- [optional] the mulitplier on interval length to wait between retries while waiting for transaction receipts (default: 1.5). - - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/provider/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. - If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/provider/types/userOperationFeeOptionsField.md). + - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. + If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md). - `maxFeePerGas`: `UserOperationFeeOptionsField` - `maxPriorityFeePerGas`: `UserOperationFeeOptionsField` diff --git a/site/packages/aa-alchemy/provider/constructor.md b/site/packages/aa-alchemy/provider/constructor.md index f9ed698b53..abcedea015 100644 --- a/site/packages/aa-alchemy/provider/constructor.md +++ b/site/packages/aa-alchemy/provider/constructor.md @@ -74,19 +74,11 @@ A new instance of an `AlchemyProvider`. - `txRetryMulitplier: string | undefined` -- [optional] the mulitplier on interval length to wait between retries while waiting for transaction receipts (default: 1.5). - - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/provider/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. - If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/provider/types/userOperationFeeOptionsField.md). + - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. + If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md). - `maxFeePerGas`: `UserOperationFeeOptionsField` - `maxPriorityFeePerGas`: `UserOperationFeeOptionsField` - `callGasLimit`: `UserOperationFeeOptionsField` - `verificationGasLimit`: `UserOperationFeeOptionsField` - `preVerificationGas`: `UserOperationFeeOptionsField` - -:::tip Note -The fee options set upon the provider initialization are available from each middleware of the `SmartAccountProvider`. For example, the default middlewares such as [`gasEstimator`](/packages/aa-core/provider/withGasEstimator.md) or [`feeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) apply the fee options to the estimated values if the fee options are set. -::: - -:::tip Note -If you are using your own middleware, for example a custom `feeDataGetter` using [`withFeeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) method on the provider, then the default `feeDataGetter` middleware is overriden. As you are opting out of using the default middleware, you are also responsible for handling the fee options appropriately for the fee options set upon provider initialization. -::: diff --git a/site/packages/aa-alchemy/provider/gasEstimator.md b/site/packages/aa-alchemy/provider/gasEstimator.md index 834c295ca3..f9d8cc0ac6 100644 --- a/site/packages/aa-alchemy/provider/gasEstimator.md +++ b/site/packages/aa-alchemy/provider/gasEstimator.md @@ -45,4 +45,4 @@ the resulting user operation struct after gas estimation, run as part of a middl ### `struct: Deferrable` -- the struct containing UserOperation fields, where each field may be asychronously returned from the middleware used to generate its final value. -Note: You typically will call this method as part of a middleware chain when building and sending UserOperations, so the parameters of `UserOperationStruct` should be generated for you, as long as you pass in the initial parameters needed for [sendUserOperation](/packages/aa-core/provider/sendUserOperation). +Note: You typically will call this method as part of a middleware chain when building and sending UserOperations, so the parameters of `UserOperationStruct` should be generated for you, as long as you pass in the initial parameters needed for [sendUserOperation](/packages/aa-core/smart-account-client/sendUserOperation). diff --git a/site/packages/aa-alchemy/provider/introduction.md b/site/packages/aa-alchemy/provider/introduction.md index efe625c328..1169a10f09 100644 --- a/site/packages/aa-alchemy/provider/introduction.md +++ b/site/packages/aa-alchemy/provider/introduction.md @@ -14,11 +14,11 @@ head: # AlchemyProvider -`AlchemyProvider` is an extension of the [`SmartAccountProvider`](/packages/aa-core/provider/introduction) implementation. It's a simpler interface you can use to leverage the Alchemy stack - JSON-RPC requests via API Key or JSON Web Token (JWT), Rundler (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Bundler), and Gas Manager (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Paymaster). +`AlchemyProvider` is an extension of the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/introduction) implementation. It's a simpler interface you can use to leverage the Alchemy stack - JSON-RPC requests via API Key or JSON Web Token (JWT), Rundler (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Bundler), and Gas Manager (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Paymaster). Notable differences between `AlchemyProvider` and `SmartAccountProvider` are implementations for: -1. [`gasEstimator`](/packages/aa-core/provider/withGasEstimator.md) -- overrides the base `SmartAccountProvider` gas estimator. +1. [`gasEstimator`](/packages/aa-core/smart-account-client/withGasEstimator.md) -- overrides the base `SmartAccountProvider` gas estimator. 2. [`withAlchemyGasManager`](/packages/aa-alchemy/provider/withAlchemyGasManager.md) -- adds the Alchemy Gas Manager middleware to the provider. ## Usage diff --git a/site/packages/aa-alchemy/provider/light-account-factory.md b/site/packages/aa-alchemy/provider/light-account-factory.md index 37bdf831d3..c415070e74 100644 --- a/site/packages/aa-alchemy/provider/light-account-factory.md +++ b/site/packages/aa-alchemy/provider/light-account-factory.md @@ -53,8 +53,8 @@ A Promise containing a new `AlchemyProvider` connected to a Light Account. - `txRetryMulitplier: string | undefined` -- [optional] the mulitplier on interval length to wait between retries while waiting for transaction receipts (default: 1.5). - - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/provider/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. - If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/provider/types/userOperationFeeOptionsField.md). + - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. + If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md). - `maxFeePerGas`: `UserOperationFeeOptionsField` - `maxPriorityFeePerGas`: `UserOperationFeeOptionsField` diff --git a/site/packages/aa-alchemy/provider/simulateUserOperationAssetChanges.md b/site/packages/aa-alchemy/provider/simulateUserOperationAssetChanges.md index f430b82bb2..32eec1b92a 100644 --- a/site/packages/aa-alchemy/provider/simulateUserOperationAssetChanges.md +++ b/site/packages/aa-alchemy/provider/simulateUserOperationAssetChanges.md @@ -70,6 +70,6 @@ const uo = await provider.sendUserOperation(uoStruct); - `data: Hex` - can be either `0x` or a call data string - `value?: bigint` - optionally, set the value in wei you want to send to the target -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/accounts/introduction.md b/site/packages/aa-core/accounts/introduction.md index c4bdf4df81..61c2d496a2 100644 --- a/site/packages/aa-core/accounts/introduction.md +++ b/site/packages/aa-core/accounts/introduction.md @@ -24,7 +24,7 @@ prev: ## BaseSmartContractAccount -The `BaseSmartContractAccount` is an abstract class that provides the base implementation the `ISmartContractAccount` interface to provide the ease of creating your own Smart Contract Account. Any class that extends and implements `BaseSmartContractAccount` may also expose additional methods that support its connecting [SmartAccountProvider](/packages/aa-core/provider/introduction). +The `BaseSmartContractAccount` is an abstract class that provides the base implementation the `ISmartContractAccount` interface to provide the ease of creating your own Smart Contract Account. Any class that extends and implements `BaseSmartContractAccount` may also expose additional methods that support its connecting [SmartAccountProvider](/packages/aa-core/smart-account-client/introduction). `BaseSmartContractAccount` contains abstract methods that requires implementation from any class that extends the class. diff --git a/site/packages/aa-core/provider/connect.md b/site/packages/aa-core/provider/connect.md deleted file mode 100644 index 20b1e5e33b..0000000000 --- a/site/packages/aa-core/provider/connect.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: connect - - - meta - - name: description - content: Overview of the connect method on SmartAccountProvider - - - meta - - property: og:description - content: Overview of the connect method on SmartAccountProvider ---- - -# connect - -Sets the current account to the smart account returned by the given function. - -The function parameter is called with the public rpc client that is used by this provider so the account can make RPC calls. - -This function emits `connect` and `accountsChanged` events to notify listeners about the connection. - -## Usage - -::: code-group - -<<< @/snippets/provider.ts - -::: - -## Returns - -### SmartAccountProvider - -The provider with the account connected - -## Parameters - -### `fn: (provider: PublicErc4337Client) => BaseSmartContractAccount` - -The function that given public rpc client, returns a smart account diff --git a/site/packages/aa-core/provider/constructor.md b/site/packages/aa-core/provider/constructor.md deleted file mode 100644 index 75c237a772..0000000000 --- a/site/packages/aa-core/provider/constructor.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: SmartAccountProvider • constructor - - - meta - - name: description - content: Overview of the constructor method on SmartAccountProvider in aa-core - - - meta - - property: og:description - content: Overview of the constructor method on SmartAccountProvider in aa-core ---- - -# constructor - -To initialize a `SmartAccountProvider`, you must provide a set of parameters detailed below. - -## Usage - -::: code-group - -```ts [example.ts] -import { SmartAccountProvider } from "@alchemy/aa-core"; -import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; -import { sepolia } from "@alchemy/aa-core"; - -// instantiates using every possible parameter, as a reference -export const provider = new SmartAccountProvider({ - rpcProvider: "ALCHEMY_RPC_URL", - chain: sepolia, - entryPointAddress: getDefaultEntryPointAddress(sepolia), - opts: { - txMaxRetries: 10, - txRetryIntervalMs: 2_000, - txRetryMulitplier: 1.5, - minPriorityFeePerBid: 100_000_000n, - }, -}); -``` - -::: - -## Returns - -### `SmartAccountProvider` - -A new instance of a `SmartAccountProvider`. - -## Parameters - -### `config: SmartAccountProviderConfig` - -- `rpcProvider: string | PublicErc4337Client` -- a JSON-RPC URL, or a viem Client that supports ERC-4337 methods and Viem public actions. See [createPublicErc4337Client](/packages/aa-core/client/createPublicErc4337Client.md). - -- `chain: Chain` -- the chain on which to create the provider. - -- `entryPointAddress: Address | undefined` -- [optional] the entry point contract address. If not provided, the entry point contract address for the provider is the connected account's entry point contract, or if not connected, falls back to the default entry point contract for the chain. See [getDefaultEntryPointAddress](/packages/aa-core/utils/getDefaultEntryPointAddress.html#getdefaultentrypointaddress). - -- `opts: SmartAccountProviderOpts | undefined` -- [optional] overrides on provider config variables having to do with fetching transaction receipts and fee computation. - - - `txMaxRetries: string | undefined` -- [optional] the maximum number of times to try fetching a transaction receipt before giving up (default: 5). - - - `txRetryIntervalMs: string | undefined` -- [optional] the interval in milliseconds to wait between retries while waiting for transaction receipts (default: 2_000). - - - `txRetryMulitplier: string | undefined` -- [optional] the mulitplier on interval length to wait between retries while waiting for transaction receipts (default: 1.5). - - - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/provider/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. - If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/provider/types/userOperationFeeOptionsField.md). - - - `maxFeePerGas`: `UserOperationFeeOptionsField` - - `maxPriorityFeePerGas`: `UserOperationFeeOptionsField` - - `callGasLimit`: `UserOperationFeeOptionsField` - - `verificationGasLimit`: `UserOperationFeeOptionsField` - - `preVerificationGas`: `UserOperationFeeOptionsField` - -:::tip Note -The fee options set upon the provider initialization are available from each middleware of the `SmartAccountProvider`. For example, the default middlewares such as [`gasEstimator`](/packages/aa-core/provider/withGasEstimator.md) or [`feeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) apply the fee options to the estimated values if the fee options are set. -::: - -:::tip Note -If you are using your own middleware, for example a custom `feeDataGetter` using [`withFeeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) method on the provider, then the default `feeDataGetter` middleware is overriden. As you are opting out of using the default middleware, you are also responsible for handling the fee options appropriately for the fee options set upon provider initialization. -::: diff --git a/site/packages/aa-core/provider/disconnect.md b/site/packages/aa-core/provider/disconnect.md deleted file mode 100644 index 14e0041716..0000000000 --- a/site/packages/aa-core/provider/disconnect.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: disconnect - - - meta - - name: description - content: Overview of the disconnect method on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the disconnect method on ISmartAccountProvider ---- - -# disconnect - -Allows for disconnecting the account from the provider so that the provider can connect to another account instance. - -This function emits `disconnect` and `accountsChanged` events to notify listeners about the connection. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; -// [!code focus:99] -await provider.disconnect(); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `ISmartAccountProvider` - -The provider with the account disconnected diff --git a/site/packages/aa-core/provider/extend.md b/site/packages/aa-core/provider/extend.md deleted file mode 100644 index 494f097a3a..0000000000 --- a/site/packages/aa-core/provider/extend.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: extend - - - meta - - name: description - content: Overview of the extend method on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the extend method on ISmartAccountProvider -next: Types ---- - -# extend - -Allows you to add additional functionality and utility methods to this provider via a decorator pattern. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -const extendedProvider = provider.extend((provider) => ({ - debugSendUserOperation: (...args) => { - console.log("debugging send user operation"); - return provider.sendUserOperation(...args); - }, -})); - -extendedProvider.debugSendUserOperation(...); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `this & R` - -Where `R` is the return type of the decorator function. - -::: warning -The extend method will not allow you to override existing methods or properties on the provider. To do this, you'll have to use class inheritance. -::: - -## Parameters - -### `decoratorFn: (provider: this) => R` - -A lambda function that takes the current provider as input and returns a set of extension methods and properties to add to the provider. diff --git a/site/packages/aa-core/provider/introduction.md b/site/packages/aa-core/provider/introduction.md deleted file mode 100644 index f029678657..0000000000 --- a/site/packages/aa-core/provider/introduction.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: SmartAccountProvider - - - meta - - name: description - content: Introduction to SmartAccountProvider exported by aa-core provider - - - meta - - property: og:description - content: Introduction to SmartAccountProvider exported by aa-core provider ---- - -# Introduction to SmartAccountProvider - -The `SmartAccountProvider` is an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compliant Provider that wraps JSON RPC methods and some Wallet Methods (signing, sendTransaction, etc). With this Provider, you can submit User Operations to RPC providers, estimate gas, configure a Paymaster, send standard JSON RPC requests, and more. It is not opinionated about which RPC provider you are using and is configurable to work with any RPC provider. Because it implements EIP-1193, it can be used with any web3 library. - -## Usage - -<<< @/snippets/core-provider.ts diff --git a/site/packages/aa-core/provider/isConnected.md b/site/packages/aa-core/provider/isConnected.md deleted file mode 100644 index b3ccd492d3..0000000000 --- a/site/packages/aa-core/provider/isConnected.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: isConnected - - - meta - - name: description - content: Overview of the isConnected method on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the isConnected method on ISmartAccountProvider ---- - -# isConnected - -Returns the boolean flag indicating if the account is connected. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; -// [!code focus:99] -const isConnected = await provider.isConnected(); -``` - -<<< @/snippets/provider.ts - -::: - -## Returns - -### `boolean` - -The boolean flag indicating if the account is connected diff --git a/site/packages/aa-core/provider/withCustomMiddleware.md b/site/packages/aa-core/provider/withCustomMiddleware.md deleted file mode 100644 index 67449d2c54..0000000000 --- a/site/packages/aa-core/provider/withCustomMiddleware.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: ISmartAccountProvider • withCustomMiddleware - - - meta - - name: description - content: Overview of the withCustomMiddleware method and accessing the customMiddleware readonly field on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the withCustomMiddleware method and accessing the customMiddleware readonly field on ISmartAccountProvider ---- - -# withCustomMiddleware - -Adds a function to the end of the middleware call stack before signature verification. It can be used to override or add additional functionality. Like modifying the user operation, making an additional RPC call, or logging data. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -// Define the custom middleware override function // [!code focus:99] -// The function below just changes the call data for the userOp -// But you can do anything you want here -const CustomMiddlewareOverrideFunction = async (uoStruct) => { - uoStruct.callData = "0xNEW_CALL_DATA"; // Changing the call data - return uoStruct; -}; - -// Add the custom middleware -provider.withCustomMiddleware(CustomMiddlewareOverrideFunction); - -// Defining the user operation data -const userOpData = { - target: "0xTARGET_ADDRESS", // Replace with the actual target address - data: "0xSOME_DATA", // Replace with the actual data -}; - -// function to call buildUserOperation and log the modified callData -const resultingUO = await provider.buildUserOperation(userOpData); -console.log("Modified callData:", resultingUO.callData); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `ISmartAccountProvider` - -An updated instance of the provider, which now uses the custom middleware. - -## Parameters - -### `override: AccountMiddlewareFn` - -The User Operation (UO) transform function that will run as the custom middleware. - -## `customMiddleware` - -The `customMiddleware` is a readonly field that represents the final middleware step in the stack. It allows overriding any of the results returned by previous middlewares, ensuring customized processing of user operations. - -You can access the current middleware configuration for the provider via: - -```ts -const currentMiddleware = provider.customMiddleware; -``` diff --git a/site/packages/aa-core/provider/withFeeDataGetter.md b/site/packages/aa-core/provider/withFeeDataGetter.md deleted file mode 100644 index 254b61fb61..0000000000 --- a/site/packages/aa-core/provider/withFeeDataGetter.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: ISmartAccountProvider • withFeeDataGetter - - - meta - - name: description - content: Overview of the withFeeDataGetter method and accessing the feeDataGetter readonly field on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the withFeeDataGetter method and accessing the feeDataGetter readonly field on ISmartAccountProvider ---- - -# withFeeDataGetter - -Overrides the default [`feeDataGetter`](#feedatagetter) middleware. This middleware is used for setting the `maxFeePerGas` and `maxPriorityFeePerGas` fields on the `UserOperation` (UO) prior to its execution. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -// Define the FeeDataMiddlewareOverrideFunction // [!code focus:99] -const FeeDataMiddlewareOverrideFunction = async () => ({ - // For demonstration purposes, we're setting hardcoded fee values. - // In a real-world scenario, you might fetch these values from a service - // Or make other determinations. - - // Setting the max fee per gas - maxFeePerGas: 100_000_000_000n, - - // Setting the max priority fee per gas - maxPriorityFeePerGas: 100_000_000_000n, -}); - -// Integrate the custom fee data middleware with the provider -provider.withFeeDataGetter(FeeDataMiddlewareOverrideFunction); - -// Define the user operation data -const userOpData = { - target: "0xTARGET_ADDRESS", // Replace with your actual target address - data: "0xSOME_DATA", // Replace with your actual data -}; - -const resultingUO = await provider.buildUserOperation(userOpData); -console.log("Modified maxFeePerGas:", resultingUO.maxFeePerGas); -console.log("Modified maxPriorityFeePerGas:", resultingUO.maxPriorityFeePerGas); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `ISmartAccountProvider` - -An updated instance of the provider, which now uses the overridden `feeDataGetter` middleware. - -## Parameters - -### `override: FeeDataMiddleware` - -A function for overriding the default `feeDataGetter` middleware. This middleware is specifically utilized to set the fee-related fields (`maxFeePerGas` and `maxPriorityFeePerGas`) on the UO before it's executed. - -## `feeDataGetter` - -The `feeDataGetter` is a readonly field on the `ISmartAccountProvider` interface that represents the default fee data getter middleware. It's used to set the fee-related fields on a UO by making calls to the connected `rpcClient` to estimate the maximum priority fee per gas and retrieve fee data. - -You can access the current fee data getter configuration for the provider via: - -```ts -const currentFeeDataGetter = provider.feeDataGetter; -``` diff --git a/site/packages/aa-core/provider/withGasEstimator.md b/site/packages/aa-core/provider/withGasEstimator.md deleted file mode 100644 index ebd44704e7..0000000000 --- a/site/packages/aa-core/provider/withGasEstimator.md +++ /dev/null @@ -1,80 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: ISmartAccountProvider • withGasEstimator - - - meta - - name: description - content: Overview of the withGasEstimator method on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the withGasEstimator method on ISmartAccountProvider ---- - -# withGasEstimator - -Override the [`gasEstimator`](#gasEstimator) middleware. - -This middleware is used for setting the `callGasLimit`, `preVerificationGas`, and `verificationGasLimit` fields on the `UserOperation` (UO) prior to its execution. This middleware is between the `feeDataGetter` middleware and the `paymasterDataMiddleware`. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -// Define the GasEstimatorMiddlewareOverrideFunction // [!code focus:99] -const GasEstimatorMiddlewareOverrideFunction = async () => { - // For demonstration purposes, we're setting hardcoded gas values. - // In a real-world scenario, you might fetch these values from a service - // Or make other determinations. - return { - callGasLimit: 0n, - preVerificationGas: 0n, - verificationGasLimit: 0n, - }; -}; - -// Integrate the custom gas estimator middleware with the provider -provider.withGasEstimator(GasEstimatorMiddlewareOverrideFunction); - -// Define the user operation data -const userOpData = { - target: "0xTARGET_ADDRESS", // Replace with your actual target address - data: "0xSOME_DATA", // Replace with your actual data -}; - -const resultingUO = await provider.buildUserOperation(userOpData); -console.log("Modified callGasLimit:", resultingUO.callGasLimit); -console.log("Modified preVerificationGas:", resultingUO.preVerificationGas); -console.log("Modified verificationGasLimit:", resultingUO.verificationGasLimit); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `SmartAccountProvider` - -An updated instance of the provider, which now uses the overridden `gasEstimator` middleware. - -## Parameters - -### `override: GasEstimatorMiddleware` - -A function for overriding the default gas estimator middleware. This middleware is specifically utilized to set the gas-related fields (`callGasLimit`, `preVerificationGas`, and `verificationGasLimit`) on the UO before it's executed. - -## `gasEstimator` - -The `gasEstimator` is a readonly field on the `ISmartAccountProvider` interface that represents the default gas estimator middleware. - -It's used to set the gas-related fields on a UO by making calls to the connected `rpcClient` to estimate the user operation gas limits. - -You can access the current fee data getter configuration for the provider via: - -```ts -const currentGasEstimator = provider.gasEstimator; -``` diff --git a/site/packages/aa-core/provider/withPaymasterMiddleware.md b/site/packages/aa-core/provider/withPaymasterMiddleware.md deleted file mode 100644 index 0ff549c480..0000000000 --- a/site/packages/aa-core/provider/withPaymasterMiddleware.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: ISmartAccountProvider • withPaymasterMiddleware - - - meta - - name: description - content: Overview of the withPaymasterMiddleware method on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the withPaymasterMiddleware method on ISmartAccountProvider ---- - -# withPaymasterMiddleware - -Override the default dummy paymaster data middleware and paymaster data middleware which set the `paymasterAndData` field during `sendUserOperation` calls. - -The `withPaymasterMiddleware` method has two overrides - `dummyPaymasterData` and `paymasterAndData` generator functions. This `dummyPaymasterData` is needed to estimate gas correctly when using a paymaster and is specific to the paymaster you're using. The second override is the actual `paymasterAndData` generator function. This function is called after gas estimation and fee estimation and is used to set the `paymasterAndData` field. The default `dummyPaymasterData` generator function returns `0x` for both the `paymasterAndData` fields. The default `paymasterAndData` generator function returns `0x` for both the `paymasterAndData` fields. - -These middleware are often used together. The dummy paymaster data is used in gas estimation before we actually have paymaster data. Because the paymaster data has an impact on the gas estimation, it's good to supply dummy paymaster data that is valid for your paymaster contract. - -It's recommend to use this middleware if you want more customization over the gas and fee estimation middleware, including setting non-default buffer values for the fee/gas estimation. You can also use `AlchemyProvider`'s [`withAlchemyGasManager`](/packages/aa-alchemy/provider/withAlchemyGasManager) method to simply the interface for these middleware. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -// Define the DummyPaymasterDataMiddlewareOverrideFunction // [!code focus:99] -const DummyPaymasterDataMiddlewareOverrideFunction = async (uoStruct) => { - // Return an object like {paymasterAndData: "0x..."} where "0x..." is the valid paymasterAndData for your paymaster contract (used in gas estimation) - // You can even hardcode these dummy singatures - // You can read up more on dummy signatures here: https://www.alchemy.com/blog/dummy-signatures-and-gas-token-transfers - const paymasterAndData = await someFunctionToFetchDummyPaymasterAndData(); - - return { - paymasterAndData, - }; -}; - -// Define the PaymasterDataMiddlewareOverrideFunction // [!code focus:99] -const PaymasterDataMiddlewareOverrideFunction = async (uoStruct) => { - // Return at minimum {paymasterAndData: "0x..."}, can also return gas estimates - const paymasterAndData = await someFunctionToFetchPaymasterAndData(); - - return { - paymasterAndData, - }; -}; - -// Integrate the dummy paymaster data middleware and paymaster data middleware middleware with the provider -provider.withPaymasterMiddleware({ - DummyPaymasterDataMiddlewareOverrideFunction, - PaymasterDataMiddlewareOverrideFunction, -}); - -// Define the user operation data -const userOpData = { - target: "0xTARGET_ADDRESS", // Replace with your actual target address - data: "0xSOME_DATA", // Replace with your actual data -}; - -const resultingUO = await provider.buildUserOperation(userOpData); -console.log("Modified paymasterAndData:", resultingUO.paymasterAndData); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `ISmartAccountProvider` - -An updated instance of the provider, which now uses the overridden `dummyPaymasterDataMiddleware` and/or `paymasterDataMiddleware` middlewares. - -## Parameters - -### `overrides: {dummyPaymasterDataMiddleware, paymasterDataMiddleware}` - -- `dummyPaymasterDataMiddleware?: PaymasterAndDataMiddleware` - `dummyPaymasterData` generator function specific to the paymaster you are using to estimate gas correctly. Default: `0x` for both the `paymasterAndData` fields. You should implement your own middleware to override these or extend this class and provider your own implemenation. -- `paymasterDataMiddleware?: PaymasterAndDataMiddleware` - `paymasterAndData` generator function called after gas estimation and fee estimated used to set the `paymasterAndData` field. Default: `0x` for both the `paymasterAndData` fields. These are dependent on the specific paymaster being used. You should implement your own middleware to override these or extend this class and provider your own implemenation. - -## `dummyPaymasterDataMiddleware` - -The `dummyPaymasterDataMiddleware` is a readonly field on the `ISmartAccountProvider` interface that represents the default dummy paymaster data middleware. It's used to set the `paymasterAndData` fields on a `UserOperation` (UO). - -You can access the current dummy paymaster data middleware configuration for the provider via: - -```ts -const currentDummyPaymasterDataMiddleware = - provider.dummyPaymasterDataMiddleware; -``` - -## `paymasterDataMiddleware` - -The `paymasterDataMiddleware` is a readonly field on the `ISmartAccountProvider` interface that represents the default paymaster data middleware. It's used to set the `paymasterAndData` field on a UO. - -You can access the current paymaster data middleware configuration for the provider via: - -```ts -const currentPaymasterDataMiddleware = provider.paymasterDataMiddleware; -``` diff --git a/site/packages/aa-core/provider/withUOSimulationMiddleware.md b/site/packages/aa-core/provider/withUOSimulationMiddleware.md deleted file mode 100644 index 7f0f2fc848..0000000000 --- a/site/packages/aa-core/provider/withUOSimulationMiddleware.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -outline: deep -head: - - - meta - - property: og:title - content: ISmartAccountProvider • withUOSimulationMiddleware - - - meta - - name: description - content: Overview of the withUOSimulationMiddleware method and accessing the simulateUOMiddleware readonly field on ISmartAccountProvider - - - meta - - property: og:description - content: Overview of the withUOSimulationMiddleware method and accessing the simulateUOMiddleware readonly field on ISmartAccountProvider ---- - -# withUOSimulationMiddleware - -Adds a function to the end of the middleware call stack to simulate the constructed `UserOperation`. It can be used to override or add additional functionality, but the typical use case would be to simulate the `uoStruct` and throwing an error if the method for simulation fails, or just pass-through the chained `uoStruct` if simulation passes. - -## Usage - -::: code-group - -```ts [example.ts] -import { provider } from "./provider"; - -// Define the simulation middleware override function // [!code focus:99] -const SimulateUOMiddlewareOverrideFunction = async (uoStruct) => { - try { - const uoSimResult = await someMethodSimulatingTheUserOperation(); - } catch (e) { - throw new Error(e); - } - - return uoStruct; -}; - -// Add the custom middleware -provider.withUOSimulationMiddleware(SimulateUOMiddlewareOverrideFunction); - -// function to call buildUserOperation which will simulate the user operation -const resultingUO = await provider.buildUserOperation(userOpData); -``` - -<<< @/snippets/provider.ts -::: - -## Returns - -### `ISmartAccountProvider` - -An updated instance of the provider, which now uses the simulation middleware. - -## Parameters - -### `override: AccountMiddlewareFn` - -The User Operation (UO) transform function that will run as the simulation middleware. - -## `simulateUOMiddleware` - -The `simulateUOMiddleware` is a readonly field that represents the final middleware step in the stack. It allows overriding any of the results returned by previous middlewares, but the typical use case would be to simulate the `uoStruct` and throwing an error if the method for simulation fails, and just pass-through the chained `uoStruct` if simulation passes. - -You can access the current `simulateUOMiddleware` configuration for the provider via: - -```ts -const currentMiddleware = provider.simulateUOMiddleware; -``` diff --git a/site/packages/aa-core/provider/buildUserOperation.md b/site/packages/aa-core/smart-account-client/actions/buildUserOperation.md similarity index 95% rename from site/packages/aa-core/provider/buildUserOperation.md rename to site/packages/aa-core/smart-account-client/actions/buildUserOperation.md index 8a59c8940b..17850e067f 100644 --- a/site/packages/aa-core/provider/buildUserOperation.md +++ b/site/packages/aa-core/smart-account-client/actions/buildUserOperation.md @@ -75,6 +75,6 @@ A Promise containing the _unsigned_ UO struct resulting from the middleware pipe - `data: Hex` - can be either `0x` or a call data string - `value?: bigint` - optionally, set the value in wei you want to send to the target -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/buildUserOperationFromTx.md b/site/packages/aa-core/smart-account-client/actions/buildUserOperationFromTx.md similarity index 94% rename from site/packages/aa-core/provider/buildUserOperationFromTx.md rename to site/packages/aa-core/smart-account-client/actions/buildUserOperationFromTx.md index 78d342f792..b6293372cc 100644 --- a/site/packages/aa-core/provider/buildUserOperationFromTx.md +++ b/site/packages/aa-core/smart-account-client/actions/buildUserOperationFromTx.md @@ -60,6 +60,6 @@ A Promise containing the _unsigned_ UO struct converted from the input transacti The `RpcTransactionRequest` object representing a traditional ethereum transaction -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/checkGasSponsorshipEligibility.md b/site/packages/aa-core/smart-account-client/actions/checkGasSponsorshipEligibility.md similarity index 95% rename from site/packages/aa-core/provider/checkGasSponsorshipEligibility.md rename to site/packages/aa-core/smart-account-client/actions/checkGasSponsorshipEligibility.md index 3a1e6823c3..4c02b176c4 100644 --- a/site/packages/aa-core/provider/checkGasSponsorshipEligibility.md +++ b/site/packages/aa-core/smart-account-client/actions/checkGasSponsorshipEligibility.md @@ -59,6 +59,6 @@ A Promise containing the boolean value indicating whether the UO to be sent is e - `data: Hex` - can be either `0x` or a call data string - `value?: bigint` - optionally, set the value in wei you want to send to the target -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/dropAndReplaceUserOperation.md b/site/packages/aa-core/smart-account-client/actions/dropAndReplaceUserOperation.md similarity index 93% rename from site/packages/aa-core/provider/dropAndReplaceUserOperation.md rename to site/packages/aa-core/smart-account-client/actions/dropAndReplaceUserOperation.md index e3bf32dde5..1c74fcbcbd 100644 --- a/site/packages/aa-core/provider/dropAndReplaceUserOperation.md +++ b/site/packages/aa-core/smart-account-client/actions/dropAndReplaceUserOperation.md @@ -51,6 +51,6 @@ A Promise containing the hash of the user operation and the request that was sen A previously submitted `UserOperation`. -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/getAddress.md b/site/packages/aa-core/smart-account-client/actions/getAddress.md similarity index 100% rename from site/packages/aa-core/provider/getAddress.md rename to site/packages/aa-core/smart-account-client/actions/getAddress.md diff --git a/site/packages/aa-core/provider/getEntryPointAddress.md b/site/packages/aa-core/smart-account-client/actions/getEntryPointAddress.md similarity index 100% rename from site/packages/aa-core/provider/getEntryPointAddress.md rename to site/packages/aa-core/smart-account-client/actions/getEntryPointAddress.md diff --git a/site/packages/aa-core/provider/getUserOperationByHash.md b/site/packages/aa-core/smart-account-client/actions/getUserOperationByHash.md similarity index 100% rename from site/packages/aa-core/provider/getUserOperationByHash.md rename to site/packages/aa-core/smart-account-client/actions/getUserOperationByHash.md diff --git a/site/packages/aa-core/provider/getUserOperationReceipt.md b/site/packages/aa-core/smart-account-client/actions/getUserOperationReceipt.md similarity index 100% rename from site/packages/aa-core/provider/getUserOperationReceipt.md rename to site/packages/aa-core/smart-account-client/actions/getUserOperationReceipt.md diff --git a/site/packages/aa-core/provider/request.md b/site/packages/aa-core/smart-account-client/actions/request.md similarity index 100% rename from site/packages/aa-core/provider/request.md rename to site/packages/aa-core/smart-account-client/actions/request.md diff --git a/site/packages/aa-core/provider/sendTransaction.md b/site/packages/aa-core/smart-account-client/actions/sendTransaction.md similarity index 93% rename from site/packages/aa-core/provider/sendTransaction.md rename to site/packages/aa-core/smart-account-client/actions/sendTransaction.md index b25305778d..c8a426a25c 100644 --- a/site/packages/aa-core/provider/sendTransaction.md +++ b/site/packages/aa-core/smart-account-client/actions/sendTransaction.md @@ -54,6 +54,6 @@ A Promise containing the transaction hash The `RpcTransactionRequest` object representing a traditional ethereum transaction -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/sendTransactions.md b/site/packages/aa-core/smart-account-client/actions/sendTransactions.md similarity index 94% rename from site/packages/aa-core/provider/sendTransactions.md rename to site/packages/aa-core/smart-account-client/actions/sendTransactions.md index 011acd3f0a..02f8562eb3 100644 --- a/site/packages/aa-core/provider/sendTransactions.md +++ b/site/packages/aa-core/smart-account-client/actions/sendTransactions.md @@ -75,6 +75,6 @@ A Promise containing the transaction hash An `RpcTransactionRequest` array representing a traditional ethereum transaction -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/sendUserOperation.md b/site/packages/aa-core/smart-account-client/actions/sendUserOperation.md similarity index 95% rename from site/packages/aa-core/provider/sendUserOperation.md rename to site/packages/aa-core/smart-account-client/actions/sendUserOperation.md index 3ce27cd3cf..1b3a0cc071 100644 --- a/site/packages/aa-core/provider/sendUserOperation.md +++ b/site/packages/aa-core/smart-account-client/actions/sendUserOperation.md @@ -73,6 +73,6 @@ A Promise containing the hash of the user operation and the request that was sen - `data: Hex` - can be either `0x` or a call data string - `value?: bigint` - optionally, set the value in wei you want to send to the target -### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/provider/types/userOperationOverrides.md) +### `overrides?:` [`UserOperationOverrides`](/packages/aa-core/smart-account-client/types/userOperationOverrides.md) Optional parameter where you can specify override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData` on the user operation request diff --git a/site/packages/aa-core/provider/signMessage.md b/site/packages/aa-core/smart-account-client/actions/signMessage.md similarity index 100% rename from site/packages/aa-core/provider/signMessage.md rename to site/packages/aa-core/smart-account-client/actions/signMessage.md diff --git a/site/packages/aa-core/provider/signMessageWith6492.md b/site/packages/aa-core/smart-account-client/actions/signMessageWith6492.md similarity index 100% rename from site/packages/aa-core/provider/signMessageWith6492.md rename to site/packages/aa-core/smart-account-client/actions/signMessageWith6492.md diff --git a/site/packages/aa-core/provider/signTypedData.md b/site/packages/aa-core/smart-account-client/actions/signTypedData.md similarity index 100% rename from site/packages/aa-core/provider/signTypedData.md rename to site/packages/aa-core/smart-account-client/actions/signTypedData.md diff --git a/site/packages/aa-core/provider/signTypedDataWith6492.md b/site/packages/aa-core/smart-account-client/actions/signTypedDataWith6492.md similarity index 100% rename from site/packages/aa-core/provider/signTypedDataWith6492.md rename to site/packages/aa-core/smart-account-client/actions/signTypedDataWith6492.md diff --git a/site/packages/aa-core/provider/waitForUserOperationTransaction.md b/site/packages/aa-core/smart-account-client/actions/waitForUserOperationTransaction.md similarity index 92% rename from site/packages/aa-core/provider/waitForUserOperationTransaction.md rename to site/packages/aa-core/smart-account-client/actions/waitForUserOperationTransaction.md index da029b5098..9c5cbc0914 100644 --- a/site/packages/aa-core/provider/waitForUserOperationTransaction.md +++ b/site/packages/aa-core/smart-account-client/actions/waitForUserOperationTransaction.md @@ -16,7 +16,7 @@ head: Attempts to fetch for UserOperationReceipt `txMaxRetries` amount of times, at an interval of `txRetryIntervalMs` milliseconds (with a multiplier of `txRetryMulitplier`) using the connected account. -Note: For more details on how to modify the retry configurations for this method, see the [constructor](/packages/aa-core/provider/constructor.md) parameters. +Note: For more details on how to modify the retry configurations for this method, see the [constructor](/packages/aa-core/smart-account-client/createSmartAccountClient.md) parameters. ## Usage diff --git a/site/packages/aa-core/smart-account-client/index.md b/site/packages/aa-core/smart-account-client/index.md new file mode 100644 index 0000000000..cbef421e6f --- /dev/null +++ b/site/packages/aa-core/smart-account-client/index.md @@ -0,0 +1,132 @@ +--- +outline: deep +head: + - - meta + - property: og:title + content: SmartAccountClient + - - meta + - name: description + content: Introduction to SmartAccountClient exported by aa-core provider + - - meta + - property: og:description + content: Introduction to SmartAccountClient exported by aa-core provider +--- + +# Smart Account Client + +The `SmartAccountClient` is an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compliant Provider that wraps JSON RPC methods and some Wallet Methods (signing, sendTransaction, etc). With this Client, you can submit User Operations to RPC providers, estimate gas, configure a Paymaster, send standard JSON RPC requests, and more. It is not opinionated about which RPC provider you are using and is configurable to work with any RPC provider. Because it implements EIP-1193, it can be used with any web3 library. + +The `SmartAccountClient` is also an extension of the `viem` [`Client`](https://viem.sh/docs/clients/custom) class. + +## Import + +```ts +import { createSmartAccountClient } from "@alchemy/aa-core"; +``` + +## Usage + +Initialize a `SmartAcountClient` with your desired Chain and Transport using `createSmartAccountClient`, or use `createSmartAccountClientFromExisting` if you already have a [`BundlerClient`](/packages/aa-core/bundler-client) available +::: code-group + +```ts [createSmartAccountClient.ts] +import { createSmartAccountClient } from "@alchemy/aa-core"; +import { createLightAccount } from "@alchemy/aa-accounts"; +import { http } from "viem"; +import { sepolia } from "@alchemy/aa-core"; + +export const smartAccountClient = new createSmartAccountClient({ + transport: http("ALCHEMY_RPC_URL"), + chain: sepolia, + // optionally provide an account to use as context + account: await createLightAccount(lightAccountParams), +}); + +const result = await smartAccountClient.sendUserOperation({ + uo: { target: "0xaddress", data: "0x", value: 0n }, + // if you didn't pass in an account above then: + account: await createLightAccount(lightAccountParams), +}); +``` + +```ts [createSmartAccountClientFromExisting.ts] +import { + createBundlerClient, + createSmartAccountClientFromExisting, +} from "@alchemy/aa-core"; +import { http } from "viem"; +import { sepolia } from "@alchemy/aa-core"; + +// This client only has methods for directly interacting with public RPC endpoints +const bundlerClient = createBundlerClient({ + transport: http("ALCHEMY_RPC_URL"), + chain: sepolia, +}); + +const smartAccountClient = createSmartAccountClientFromExisting({ + client: bundlerClient, + // optionally provide an account to use as context + account: await createLightAccount(lightAccountParams), +}); + +const result = await smartAccountClient.sendUserOperation({ + uo: { target: "0xaddress", data: "0x", value: 0n }, + // if you didn't pass in an account above then: + account: await createLightAccount(lightAccountParams), +}); +``` + +::: + +## Returns + +### `SmartAccountClient` + +A new instance of a `SmartAccountClient`. + +## Parameters + +### `config: SmartAccountClientConfig` + +#### If using `createSmartAccountClient`: + +- `transport: Transport` -- a viem [Transport](https://viem.sh/docs/clients/intro#transports) that defines how you want to interact with a JSON-RPC provider. + +- `chain: Chain` -- the chain on which to create the provider. + +#### If using `createSmartAccountClientFromExisting`: + +- `client: BundlerClient` -- a [bundler client](/packages/aa-core/bundler-client) instance that will be used to communicate with an RPC provider that supports Ethereum RPC methods. + +#### Common to both: + +- `account?: SmartContractAccount` -- [optional] the smart account to use as context for all of your calls. If not provided, then the account can be provided to each individual call instead. + +- `entryPointAddress: Address | undefined` -- [optional] the entry point contract address. If not provided, the entry point contract address for the provider is the connected account's entry point contract, or if not connected, falls back to the default entry point contract for the chain. See [getDefaultEntryPointAddress](/packages/aa-core/utils/getDefaultEntryPointAddress.html#getdefaultentrypointaddress). + +- `dummyPaymasterAndData?: ClientMiddlewareFn` -- [optional] an override for the dummy paymaster and data middleware. This is useful if you want to use a paymaster. The `dummyPaymasterAndData` middleware function is run before all other middlewares and is used during gas and fee estimation. It should be a value that does not cause your paymaster to revert. + +- `feeEstimator?: ClientMiddlewareFn` -- [optional] an override for the fee estimator middleware. The `feeEstimator` middleware function calculates `maxFeePerGas` and `maxPriorityFeePerGas` for your User Operation. + +- `gasEstimator?: ClientMiddlewareFn` -- [optional] an override for the gas estimator middleware. The `gasEstimator` middleware function calculates the gas fields of your User Operation. + +- `customMiddleware?: ClientMiddlewareFn` -- [optional] if you would like to run a custom transformation on your User Operation after Gas and Fee estimation, but before your paymaster is called, you can provide a custom middleware function here. + +- `paymasterAndData?: ClientMiddlewareFn` -- [optional] if you owuld like to use a paymaster, then this middleware must be supplied in conjunction with the above `dummyPaymasterAndData` middleware. This middleware runs after gas and fee estimation and should generate the `paymasterAndData` field that will be used to sponsor your user operation. + +- `opts: SmartAccountProviderOpts | undefined` -- [optional] overrides on provider config variables having to do with fetching transaction receipts and fee computation. + + - `txMaxRetries: string | undefined` -- [optional] the maximum number of times to try fetching a transaction receipt before giving up (default: 5). + + - `txRetryIntervalMs: string | undefined` -- [optional] the interval in milliseconds to wait between retries while waiting for transaction receipts (default: 2_000). + + - `txRetryMulitplier: string | undefined` -- [optional] the mulitplier on interval length to wait between retries while waiting for transaction receipts (default: 1.5). + + - `feeOptions:` [`UserOperationFeeOptions`](/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md) `| undefined` --[optional] user operation fee options to be used for gas estimation, set at the global level on the provider. + If not set, default fee options for the chain are used. Available fields in `feeOptions` include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` where each field is of type [`UserOperationFeeOptionsField`](/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md). + + - `maxFeePerGas`: `UserOperationFeeOptionsField` + - `maxPriorityFeePerGas`: `UserOperationFeeOptionsField` + - `callGasLimit`: `UserOperationFeeOptionsField` + - `verificationGasLimit`: `UserOperationFeeOptionsField` + - `preVerificationGas`: `UserOperationFeeOptionsField` diff --git a/site/packages/aa-core/provider/types/userOperationFeeOptions.md b/site/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md similarity index 91% rename from site/packages/aa-core/provider/types/userOperationFeeOptions.md rename to site/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md index c585702917..6759f03dc4 100644 --- a/site/packages/aa-core/provider/types/userOperationFeeOptions.md +++ b/site/packages/aa-core/smart-account-client/types/userOperationFeeOptions.md @@ -14,7 +14,7 @@ head: # UserOperationFeeOptions -Fee options object type used by the [`SmartAccountProvider`](/packages/aa-core/provider/constructor.md) during the gas fee calculation middlewares when constructing the user operation to send. +Fee options object type used by the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/createSmartAccountClient.md) during the gas fee calculation middlewares when constructing the user operation to send. For example, if the below example `UserOperationFeeOptions` is set on the provider upon initialization, the `maxPriorityFeePerGas` field on the user operation will be set as the max value between the 50% buffered `maxPriorityFeePerGas` estimate and the the min `maxPriorityFeePerGas` value specified here, `100_000_000n`. diff --git a/site/packages/aa-core/provider/types/userOperationFeeOptionsField.md b/site/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md similarity index 70% rename from site/packages/aa-core/provider/types/userOperationFeeOptionsField.md rename to site/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md index b1a619ff97..205a62ea77 100644 --- a/site/packages/aa-core/provider/types/userOperationFeeOptionsField.md +++ b/site/packages/aa-core/smart-account-client/types/userOperationFeeOptionsField.md @@ -14,9 +14,9 @@ head: # UserOperationFeeOptionsField -Merged type of [`BigNumberishRange`](/glossary/types.md#bignumberishrange) with [`Percentage`](/glossary/types.md#percentage) type that can be used as [`UserOperationFeeOptions`](./userOperationFeeOptions.md) fields for the [`SmartAccountProvider`](/packages/aa-core/provider/constructor.md) to use during the gas fee calculation middlewares when constructing the user operation to send. +Merged type of [`BigNumberishRange`](/glossary/types.md#bignumberishrange) with [`Percentage`](/glossary/types.md#percentage) type that can be used as [`UserOperationFeeOptions`](./userOperationFeeOptions.md) fields for the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/createSmartAccountClient.md) to use during the gas fee calculation middlewares when constructing the user operation to send. -For example, if the below example `UserOperationFeeOptionsField` is set as the fee option for the `maxPriorityFeePerGas` field of [`UserOperationFeeOptions`](./userOperationFeeOptions.md), then the [`SmartAccountProvider`](/packages/aa-core/provider/constructor.md) will apply 50% buffer to the estimated `maxPriorityFeePerGas`, then set the `maxPriorityFeePerGas` on the user operation as the larger value between the buffered `maxPriorityFeePerGas` fee and the min `maxPriorityFeePerGas` which is `100_000_000n` here. +For example, if the below example `UserOperationFeeOptionsField` is set as the fee option for the `maxPriorityFeePerGas` field of [`UserOperationFeeOptions`](./userOperationFeeOptions.md), then the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/createSmartAccountClient.md) will apply 50% buffer to the estimated `maxPriorityFeePerGas`, then set the `maxPriorityFeePerGas` on the user operation as the larger value between the buffered `maxPriorityFeePerGas` fee and the min `maxPriorityFeePerGas` which is `100_000_000n` here. ```ts /* diff --git a/site/packages/aa-core/provider/types/userOperationOverrides.md b/site/packages/aa-core/smart-account-client/types/userOperationOverrides.md similarity index 87% rename from site/packages/aa-core/provider/types/userOperationOverrides.md rename to site/packages/aa-core/smart-account-client/types/userOperationOverrides.md index 3dd0f07d32..f30abbdc3e 100644 --- a/site/packages/aa-core/provider/types/userOperationOverrides.md +++ b/site/packages/aa-core/smart-account-client/types/userOperationOverrides.md @@ -18,14 +18,14 @@ next: Contains override values to be applied on the user operation reqeust to be constructed or sent. Available fields include `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData`. -These override values are available from each middleware of the `SmartAccountProvider`. For example, the default middlewares such as [`gasEstimator`](/packages/aa-core/provider/withGasEstimator.md) or [`feeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) apply the overrides values to the estimated values if the override values are provided. +These override values are available from each middleware of the `SmartAccountProvider`. For example, the default middlewares such as [`gasEstimator`](/packages/aa-core/smart-account-client/withGasEstimator.md) or [`feeDataGetter`](/packages/aa-core/smart-account-client/withFeeDataGetter.md) apply the overrides values to the estimated values if the override values are provided. Other than the `paymasterAndData` field, the override fields could be either the absolute value or the percentage value. In the default middlewares, if the override value is an absolute value, it simply overrides the estimated value. If the override value is a percentage value, the estimated value is _bumped_ with the indicated percentage value. For example, if the override value is `{ percentage: 10 }` for the `maxPriorityFeePerGas` field, then 10% bump is applied to the estimated `maxPriorityFeePerGas` of the user operation. The `paymasterAndData` only allows an absolute value override, and if the override value is provided, then the paymaster middleware is bypassed entirely. Refer to our guide [How to Handle User Operations that are Not Eligible for Gas Sponsorship](/tutorials/sponsoring-gas/gas-sponsorship-eligibility.md) on the example of using the `paymasterAndData` override to bypass the paymaster middleware to fallback to the user paying the gas fee instead of the gas being subsidized by the paymaster. :::tip Note -Note that if you are using your own middleware, for example a custom `feeDataGetter` using [`withFeeDataGetter`](/packages/aa-core/provider/withFeeDataGetter.md) method on the provider, then the default `feeDataGetter` middleware is overriden. As you are opting out of using the default middleware, you are also responsible for handling the `UserOperationOverrides` appropriately. +Note that if you are using your own middleware, for example a custom `feeDataGetter` using [`withFeeDataGetter`](/packages/aa-core/smart-account-client/withFeeDataGetter.md) method on the provider, then the default `feeDataGetter` middleware is overriden. As you are opting out of using the default middleware, you are also responsible for handling the `UserOperationOverrides` appropriately. ::: ```ts diff --git a/site/packages/aa-ethers/provider-adapter/constructor.md b/site/packages/aa-ethers/provider-adapter/constructor.md index 72e5786edb..846eef6f4f 100644 --- a/site/packages/aa-ethers/provider-adapter/constructor.md +++ b/site/packages/aa-ethers/provider-adapter/constructor.md @@ -76,4 +76,4 @@ Either: Or: -- `accountProvider: SmartAccountProvider` -- See [SmartAccountProvider](/packages/aa-core/provider/constructor.md). +- `accountProvider: SmartAccountProvider` -- See [SmartAccountProvider](/packages/aa-core/smart-account-client/createSmartAccountClient.md). diff --git a/site/snippets/core-provider.ts b/site/snippets/core-provider.ts index ad7fd878ab..359cbf9225 100644 --- a/site/snippets/core-provider.ts +++ b/site/snippets/core-provider.ts @@ -1,27 +1,24 @@ -import { - LightSmartContractAccount, - getDefaultLightAccountFactoryAddress, -} from "@alchemy/aa-accounts"; +import { createLightAccount } from "@alchemy/aa-accounts"; import { LocalAccountSigner, - SmartAccountProvider, SmartAccountSigner, + createSmartAccountClient, polygonMumbai, } from "@alchemy/aa-core"; +import { http } from "viem"; const chain = polygonMumbai; -const owner: SmartAccountSigner = - LocalAccountSigner.mnemonicToAccountSigner(YOUR_OWNER_MNEMONIC); +const owner: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner( + "YOUR_OWNER_MNEMONIC" +); +const rpcTransport = http("https://polygon-mumbai.g.alchemy.com/v2/demo"); -export const provider = new SmartAccountProvider({ - rpcProvider: "https://polygon-mumbai.g.alchemy.com/v2/demo", +export const provider = createSmartAccountClient({ + transport: rpcTransport, chain, -}).connect( - (rpcClient) => - new LightSmartContractAccount({ - chain, - factoryAddress: getDefaultLightAccountFactoryAddress(chain), - rpcClient, - owner, - }) -); + account: await createLightAccount({ + transport: rpcTransport, + chain, + owner, + }), +}); diff --git a/site/tutorials/batching-transactions.md b/site/tutorials/batching-transactions.md index 050a33576c..9919740717 100644 --- a/site/tutorials/batching-transactions.md +++ b/site/tutorials/batching-transactions.md @@ -39,7 +39,7 @@ When you batch transactions, the transaction actions (`target`s and `calldata`s) The batched UO gets executed by the account calling the `executeBatch` method on the [`SimpleAccount`](https://github.com/eth-infinitism/account-abstraction/blob/ver0.6.0/contracts/samples/SimpleAccount.sol) or [`LightAccount`](https://github.com/alchemyplatform/light-account/blob/v1.0.2/src/LightAccount.sol) smart contracts. `executeBatch` processes the input array of transactions data linearly, guaranteeing the execution order of those transactions to be **sequential**. ::: -## Batching using [`sendUserOperation`](/packages/aa-core/provider/sendUserOperation.md) +## Batching using [`sendUserOperation`](/packages/aa-core/smart-account-client/sendUserOperation.md) The `SmartAccountProvider` supports passing either a single UO or an array of UOs to `sendUserOperation`. If you pass an array, the provider will batch the transactions into a single User Operation and submit it to the bundler. Let's see an example: @@ -65,7 +65,7 @@ const { hash } = await provider.sendUserOperation([ ::: -## Batching using [`sendTransactions`](/packages/aa-core/provider/sendTransactions.md) +## Batching using [`sendTransactions`](/packages/aa-core/smart-account-client/sendTransactions.md) The `SmartAccountProvider` supports sending UOs and waiting for them to be mined in a transaction via the `sendTransaction` and `sendTransactions` methods. The latter allows for batching in the same way `sendUserOperation`: diff --git a/site/tutorials/send-user-operation.md b/site/tutorials/send-user-operation.md index d60f184e1c..0ffd8d0993 100644 --- a/site/tutorials/send-user-operation.md +++ b/site/tutorials/send-user-operation.md @@ -43,7 +43,7 @@ See [Light Account](/packages/aa-accounts/light-account/introduction.md) for mor ## 3. Construct The CallData -The best part of Account Kit is that it abstracts the differences between User Operation calldata and standard Transaction calldata, such that you can pass in typical calldata to [sendUserOperation](/packages/aa-core/provider/waitForUserOperationTransaction.md) as if it was a transaction sent from your smart account, and we'll wrap it as necessary to generate calldata as it would be as a User Operation. +The best part of Account Kit is that it abstracts the differences between User Operation calldata and standard Transaction calldata, such that you can pass in typical calldata to [sendUserOperation](/packages/aa-core/smart-account-client/waitForUserOperationTransaction.md) as if it was a transaction sent from your smart account, and we'll wrap it as necessary to generate calldata as it would be as a User Operation. The second best part of Account Kit is it's build atop [viem](https://viem.sh/). This means we can leverage utility methods to easily generate calldata, with type safety, using a smart contract's ABI. @@ -53,11 +53,11 @@ Some other helpful viem methods include: [encodeFunctionData](https://viem.sh/do ## 4. Send The User Operation -Now we'll use the connected provider to send a user operation. We'll use the [sendUserOperation](/packages/aa-core/provider/sendUserOperation.md) method on the provider. +Now we'll use the connected provider to send a user operation. We'll use the [sendUserOperation](/packages/aa-core/smart-account-client/sendUserOperation.md) method on the provider. You can either send ETH to the smart account to pay for User Operation's gas, or you can connect your provider to our Gas Manager using the [withAlchemyGasManager](/packages/aa-alchemy/provider/withAlchemyGasManager.md) method to sponsor the UO's gas. We'll use the latter approach below. You can go to the [Alchemy Dashboard](https://dashboard.alchemy.com/gas-manager/?a=ak-docs) to get a Gas Manager policy ID. -We'll also want to wait for the transaction which contains the User Operation, so that we know the User Operation executed on-chain. We can use the [waitForUserOperationTransaction](/packages/aa-core/provider/waitForUserOperationTransaction.md) method on provider to do so, as seen below. +We'll also want to wait for the transaction which contains the User Operation, so that we know the User Operation executed on-chain. We can use the [waitForUserOperationTransaction](/packages/aa-core/smart-account-client/waitForUserOperationTransaction.md) method on provider to do so, as seen below. <<< @/snippets/send-uo-example/send-uo.ts diff --git a/site/tutorials/sim-user-operation.md b/site/tutorials/sim-user-operation.md index fff8a298a7..bb616d183b 100644 --- a/site/tutorials/sim-user-operation.md +++ b/site/tutorials/sim-user-operation.md @@ -42,7 +42,7 @@ There are two ways that Account Kit supports UO simulation on an `AlchemyProvide To simulate User Operations, we must connect the `provider` with the middleware to simulate `UserOperations` before sending them. This can be done in a single line code, as show below! -Then, whenever you call a method on the provider which generates the UO to send (e.g. [`sendUserOperation`](/packages/aa-core/provider/sendUserOperation), [`sendTransaction`](/packages/aa-core/provider/sendTransaction), [`sendTransactions`](/packages/aa-core/provider/sendTransactions), [`buildUserOperation`](/packages/aa-core/provider/buildUserOperation), or [`buildUserOperationFromTx`](/packages/aa-core/provider/buildUserOperationFromTx)), the provider will also simulate which assets change as a result of the UO, and if simulation fails, the provider will not send the UO unnecessarily! +Then, whenever you call a method on the provider which generates the UO to send (e.g. [`sendUserOperation`](/packages/aa-core/smart-account-client/sendUserOperation), [`sendTransaction`](/packages/aa-core/smart-account-client/sendTransaction), [`sendTransactions`](/packages/aa-core/smart-account-client/sendTransactions), [`buildUserOperation`](/packages/aa-core/smart-account-client/buildUserOperation), or [`buildUserOperationFromTx`](/packages/aa-core/smart-account-client/buildUserOperationFromTx)), the provider will also simulate which assets change as a result of the UO, and if simulation fails, the provider will not send the UO unnecessarily! ::: code-group diff --git a/site/tutorials/sponsoring-gas/gas-sponsorship-eligibility.md b/site/tutorials/sponsoring-gas/gas-sponsorship-eligibility.md index 28552eb77b..cbb2357eed 100644 --- a/site/tutorials/sponsoring-gas/gas-sponsorship-eligibility.md +++ b/site/tutorials/sponsoring-gas/gas-sponsorship-eligibility.md @@ -24,7 +24,7 @@ As mentioned from the previous guide on [How to Sponsor Gas for a User Operation But what happens when the user operation you are sending fails to satisfy the criteria set in the gas manager policy? How do you check if the user operation is eligible for gas sponsorship before sending the user operation? -If you do send the user operation that is not eligible for the gas sponsorship under your Gas Manager policy, [`sendUserOperation`](/packages/aa-core/provider/sendUserOperation.md) or [`sendTransaction`](/packages/aa-core/provider/sendTransaction.md) will fail due to the error thrown during the [`PaymasterMiddleware`](/packages/aa-core/provider/withPaymasterMiddleware.md) failure. You can follow the guide below to check for gas sponsorship eligibility in advance. +If you do send the user operation that is not eligible for the gas sponsorship under your Gas Manager policy, [`sendUserOperation`](/packages/aa-core/smart-account-client/sendUserOperation.md) or [`sendTransaction`](/packages/aa-core/smart-account-client/sendTransaction.md) will fail due to the error thrown during the [`PaymasterMiddleware`](/packages/aa-core/smart-account-client/withPaymasterMiddleware.md) failure. You can follow the guide below to check for gas sponsorship eligibility in advance. ## 1. How to Check if a User Operation is Eligible for Gas Sponsorship @@ -50,9 +50,9 @@ provider.withAlchemyGasManager({ ::: -Then, before you call `sendUserOperation` on the provider, you can use [`checkGasSponsorshipEligibility`](/packages/aa-core/provider/checkGasSponsorshipEligibility.md) to verify the eligibility of the connected account for gas sponsorship concerning the upcoming `UserOperation` (UO) that is intended to be sent. +Then, before you call `sendUserOperation` on the provider, you can use [`checkGasSponsorshipEligibility`](/packages/aa-core/smart-account-client/checkGasSponsorshipEligibility.md) to verify the eligibility of the connected account for gas sponsorship concerning the upcoming `UserOperation` (UO) that is intended to be sent. -Internally, this method invokes [`buildUserOperation`](/packages/aa-core/provider/buildUserOperation.md), which navigates through the middleware pipeline, including the `PaymasterMiddleware`. Its purpose is to construct the UO struct meant for transmission to the bundler. Following the construction of the UO struct, this function verifies if the resulting structure contains a non-empty `paymasterAndData` field. +Internally, this method invokes [`buildUserOperation`](/packages/aa-core/smart-account-client/buildUserOperation.md), which navigates through the middleware pipeline, including the `PaymasterMiddleware`. Its purpose is to construct the UO struct meant for transmission to the bundler. Following the construction of the UO struct, this function verifies if the resulting structure contains a non-empty `paymasterAndData` field. You can utilize this method before sending the user operation to confirm its eligibility for gas sponsorship. Depending on the outcome, it allows you to tailor the user experience accordingly, based on eligibility. @@ -76,7 +76,7 @@ If you attempt to execute the `sendUserOperation` method for user operations ine This section of the guide elucidates how you can circumvent the `PaymasterMiddleware`, enabling the sending of user operations without gas sponsorship. This functionality permits the sending of user operations where users pay the gas fee themselves via their smart account. -When employing various methods on `SmartAccountProvider` to send user operations (e.g., [`sendUserOperation`](/packages/aa-core/provider/sendUserOperation.md) or [`sendTransaction`](/packages/aa-core/provider/sendTransaction.md)), apart from the `UserOperationCallData` or `BatchUserOperationCallData`, you have the option to include an additional parameter named `overrides`. This parameter allows the specification of override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData`. To bypass the `PaymasterMiddleware`, you can specifically set the `paymasterAndData` override. For example, assigning an empty hex string (`0x`) to the `paymasterAndData` field in the overrides would result in the user operation being sent without the paymaster covering the gas fee, but rather paid from the user's own smart account. +When employing various methods on `SmartAccountProvider` to send user operations (e.g., [`sendUserOperation`](/packages/aa-core/smart-account-client/sendUserOperation.md) or [`sendTransaction`](/packages/aa-core/smart-account-client/sendTransaction.md)), apart from the `UserOperationCallData` or `BatchUserOperationCallData`, you have the option to include an additional parameter named `overrides`. This parameter allows the specification of override values for `maxFeePerGas`, `maxPriorityFeePerGas`, `callGasLimit`, `preVerificationGas`, `verificationGasLimit` or `paymasterAndData`. To bypass the `PaymasterMiddleware`, you can specifically set the `paymasterAndData` override. For example, assigning an empty hex string (`0x`) to the `paymasterAndData` field in the overrides would result in the user operation being sent without the paymaster covering the gas fee, but rather paid from the user's own smart account. ```ts [bypass-paymaster-middleware.ts] // If gas sponsorship ineligible, baypass paymaster middleware by passing in the paymasterAndData override