diff --git a/site/pages/smart-contracts/modular-account-v2/getting-started.mdx b/site/pages/smart-contracts/modular-account-v2/getting-started.mdx new file mode 100644 index 0000000000..aca3394390 --- /dev/null +++ b/site/pages/smart-contracts/modular-account-v2/getting-started.mdx @@ -0,0 +1,93 @@ +--- +title: Modular Account V2 • Getting started +description: Getting started with Modular Account V2 in Account Kit +--- + +# Getting started with Modular Account V2 + +It is easy to get started with Modular Account v2! Below, you will create a new Modular Account v2 client that will be used to send user operations. Your MAv2 smart account will be deployed on-chain when you send the first User Operation from a unique signer. + +## Install packages + +**Prerequisites** + +- minimum Typescript version of 5 +- pin viem to 2.20.0 (`yarn add viem@2.20.0`) + +**Installation** + +First, install the `@account-kit/smart-contracts` package. + +:::code-group + +```bash [yarn] +yarn add @account-kit/smart-contracts +yarn add @account-kit/infra +``` + +```bash [npm] +npm install @account-kit/smart-contracts +npm install @account-kit/infra +``` + +::: + +:::tip[Address calculation] +For Modular Account V2, the address of the smart account will be calculated as a combination of [the owner and the salt](https://github.com/alchemyplatform/modular-account/blob/v2.0.x/src/factory/AccountFactory.sol#L98-L104). You will get the same smart account address each time you supply the same `owner`, the signer(s) used to create the account for the first time. You can also optionally supply `salt` if you want a different address for the same `owner` param (the default salt is `0n`). + +If you want to use a signer to connect to an account whose address does not map to the contract-generated address, you can supply the `accountAddress` to connect with the account of interest. In that case, the `signer` address is not used for address calculation, but only for signing the operation. +::: + +## Creating a Modular Account V2 client + +```ts twoslash [modular-account-v2.ts] +import { createModularAccountV2Client } from "@account-kit/smart-contracts"; +import { LocalAccountSigner } from "@aa-sdk/core"; +import { sepolia, alchemy } from "@account-kit/infra"; +import { generatePrivateKey } from "viem/accounts"; + +const accountClient = await createModularAccountV2Client({ + mode: "default", // optional param to specify the MAv2 variant (either "default" or "7702") + chain: sepolia, + transport: alchemy({ apiKey: "your-api-key" }), // Get your API key at https://dashboard.alchemy.com/apps or http("RPC_URL") for non-alchemy infra + signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()), +}); +``` + +Want to enable social login methods? Set up your [Alchemy Signer](/signer/quickstart). + +Alternatively, you can [bring a 3rd party signer](/third-party/signers) as the owner of your new account. + +Not sure what signer to use? [Learn more](/signer/what-is-a-signer). + +## Sending a user operation + +Now that you have a client, you can send a User Operation. The first User Operation will also deploy the new Modular Account v2. + +```ts twoslash +import { createModularAccountV2Client } from "@account-kit/smart-contracts"; +import { LocalAccountSigner } from "@aa-sdk/core"; +import { sepolia, alchemy } from "@account-kit/infra"; +import { generatePrivateKey } from "viem/accounts"; +import { parseEther } from "viem"; + +const accountClient = await createModularAccountV2Client({ + chain: sepolia, + transport: alchemy({ apiKey: "your-api-key" }), + signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()), +}); + +const operation = await accountClient.sendUserOperation({ + // simple UO sending no data or value to vitalik's address + target: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // The address to call in the UO + data: "0x", // The calldata to send in the UO + value: parseEther("0"), // The value to send in the UO +}); + +console.log( + "User operation sent! \nUO hash: ", + operation.hash, + "\nModular Account v2 Address: ", + operation.request.sender +); +``` diff --git a/site/pages/smart-contracts/modular-account/getting-started.mdx b/site/pages/smart-contracts/modular-account/getting-started.mdx index 646fd4bc6c..02179bd402 100644 --- a/site/pages/smart-contracts/modular-account/getting-started.mdx +++ b/site/pages/smart-contracts/modular-account/getting-started.mdx @@ -22,14 +22,12 @@ First, install the `@account-kit/smart-contracts` package. ```bash [yarn] yarn add @account-kit/smart-contracts -# if using alchemy infra yarn add @account-kit/infra ``` ```bash [npm] -yarn add @account-kit/smart-contracts -# if using alchemy infra -yarn add @account-kit/infra +npm install @account-kit/smart-contracts +npm install @account-kit/infra ``` ::: diff --git a/site/sidebar/smart-contracts.ts b/site/sidebar/smart-contracts.ts index c31363b646..f91142faa2 100644 --- a/site/sidebar/smart-contracts.ts +++ b/site/sidebar/smart-contracts.ts @@ -9,6 +9,15 @@ export const smartContractsSidebar: SidebarItem[] = [ text: "Introduction", link: "/smart-contracts/choosing-a-smart-account", }, + { + text: "Modular Account V2", + items: [ + { + text: "Getting started", + link: "/smart-contracts/modular-account-v2/getting-started", + }, + ], + }, { text: "Modular Account", items: [