Skip to content

Commit

Permalink
refactor: move use-kernel-account.mdx to new directory structure
Browse files Browse the repository at this point in the history
Co-Authored-By: Kristof Gazso <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and kristofgazso committed Dec 30, 2024
1 parent 30ab727 commit 8532224
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions docs/pages/permissionless/accounts/how-to/use-kernel-account.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import VersionWarning from "../../VersionWarning"

<VersionWarning version="0.2" />

# How to create and use a Kernel account with permissionless.js

:::info
ZeroDev, the author of Kernel, maintains their own in-house SDK built closely on top of permissionless.js that you can use for the account system while still plugging in all the other components from permissionless.js. Take a look at [their documentation](https://docs.zerodev.app) for more information.
:::

[Kernel](https://github.com/zerodevapp/kernel) is a **modular smart account** that supports plugins, which are smart contracts that extend the account's functionalities. You can use Kernel with popular plugins such as session keys and account recovery, and even write your own plugins. Kernel is compatible with [ERC-7579](https://erc7579.com/).

## Picking an EntryPoint

Kernel is compatible with EntryPoint versions v0.6 and v0.7.

If you are building a new application, we recommend using EntryPoint v0.7, which gives you the latest and greatest features and optimizations. If you already have an application using Kernel on EntryPoint v0.6, just stick with it -- it will be supported indefinitely.

In this guide, we will use EntryPoint v0.7.

## Steps

::::steps

### Import the required packages

```ts
// [!include ~/snippets/accounts/kernel.ts:imports]
```

### Create the clients

First we must create the public, (optionally) pimlico paymaster clients that will be used to interact with the Kernel account.

```ts
// [!include ~/snippets/accounts/kernel.ts:clients]
```

### Create the signer

Kernel accounts can work with a variety of signing algorithms such as ECDSA, passkeys, and multisig. In permissionless.js, the default Kernel account validates ECDSA signatures. [Any signer](/permissionless/how-to/signers) can be used as a signer for the Kernel account.

For example, to create a signer based on a private key:

```ts
// [!include ~/snippets/accounts/kernel.ts:signer]
```

### Create the Kernel account

:::info
For a full list of options for creating a Kernel account, take a look at the reference documentation page for [`toEcdsaKernelSmartAccount`](/permissionless/reference/accounts/toEcdsaKernelSmartAccount).
:::

With a signer, you can create a Kernel account as such:

```ts
// [!include ~/snippets/accounts/kernel.ts:smartAccount]
```

The Kernel address is computed deterministically from the signer, but you can optionally pass an `index` to create any number of different accounts using the same signer. You can also pass an `address` to use an already created Kernel account.

### Create the smart account client

The smart account client is a permissionless.js client that is meant to serve as an almost drop-in replacement for viem's [walletClient](https://viem.sh/docs/clients/wallet.html).

```ts
// [!include ~/snippets/accounts/kernel.ts:smartAccountClient]
```

### Send a transaction

Transactions using permissionless.js simply wrap around user operations. This means you can switch to permissionless.js from your existing viem EOA codebase with minimal-to-no changes.

```ts
// [!include ~/snippets/accounts/kernel.ts:submit]
```

This also means you can also use viem Contract instances to transact without any modifications.

```ts
// [!include ~/snippets/accounts/kernel.ts:submitNft]
```

You can also send an array of transactions in a single batch.

```ts
// [!include ~/snippets/accounts/kernel.ts:submitBatch]
```

::::

0 comments on commit 8532224

Please sign in to comment.