Skip to content

Commit

Permalink
docs: add ma v2 page (#1340)
Browse files Browse the repository at this point in the history
* docs: add ma v2 page

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* fix: review fixes

* chore: remove comment to standardize

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* fix: imports in example

* fix: lint

* Update site/pages/smart-contracts/modular-account-v2/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* Update site/pages/smart-contracts/modular-account/getting-started.mdx

Co-authored-by: avarobinson <[email protected]>

* chore: make it consistent

---------

Co-authored-by: avarobinson <[email protected]>
  • Loading branch information
howydev and avarobinson committed Feb 14, 2025
1 parent f7c7911 commit adfebbc
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
93 changes: 93 additions & 0 deletions site/pages/smart-contracts/modular-account-v2/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -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 [email protected]`)

**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
);
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

:::
Expand Down
9 changes: 9 additions & 0 deletions site/sidebar/smart-contracts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit adfebbc

Please sign in to comment.