-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
site/pages/smart-contracts/modular-account-v2/getting-started.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
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! We will show you two different ways using Alchemy Infra or 3rd party infra. | ||
|
||
## 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 | ||
# 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 | ||
``` | ||
|
||
::: | ||
|
||
## With Alchemy Infra | ||
|
||
Then you can do the following: | ||
|
||
```ts twoslash | ||
import { createModularAccountV2Client } from "@account-kit/smart-contracts"; | ||
import { sepolia, alchemy } from "@account-kit/infra"; | ||
import { LocalAccountSigner } from "@aa-sdk/core"; | ||
import { generatePrivateKey } from "viem/accounts"; | ||
|
||
const alchemyAccountClient = await createModularAccountV2Client({ | ||
transport: alchemy({ apiKey: "your-api-key" }), | ||
chain: sepolia, | ||
signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()), | ||
}); | ||
``` | ||
|
||
:::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. | ||
::: | ||
|
||
## With 3rd-party infra | ||
|
||
If you're using a 3rd-party for infra, we also expose a client that you can use to interact with Modular Account V2 using other RPC providers. | ||
|
||
```ts twoslash | ||
import { createModularAccountV2Client } from "@account-kit/smart-contracts"; | ||
import { LocalAccountSigner } from "@aa-sdk/core"; | ||
import { sepolia } from "viem/chains"; | ||
import { http } from "viem"; | ||
import { generatePrivateKey } from "viem/accounts"; | ||
|
||
const accountClient = await createModularAccountV2Client({ | ||
chain: sepolia, | ||
transport: http("RPC_URL"), | ||
signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()), | ||
}); | ||
``` | ||
|
||
Next, if you want to use a different `signer` with a smart account signer, check out [choosing a signer](/signer/what-is-a-signer). Otherwise, if you are ready to get on-chain, go to [send user operations](/infra/send-user-operations). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.