Skip to content

How to install and uninstall plugins on a Modular Account

ERC-6900 Modular Accounts implements Plugin manager interface IPluginManager.sol to support installing and uninstalling plugins on a Modular Account. This contract interface defines the method installPlugin() and uninstallPlugin() that clients can use to install or uninstall plugins on a Modular Account.

Account Kit provides a streamlined experience of interacting with the Modular Account AccoutLoupe interface easily by providing pluginManagerActions defined in @alchemy/aa-accounts package. When you connect your Modular Account to SmartAccountClient you can extend the client with pluginManagerActions, which exposes a set of methods available to call the account AccountLoupe with the client connected to the account.

There are two ways to install plugins. The first method is to use the pluginManagerActions's generic installPlugin method, but this method requires the PluginGenConfig configure the correct plugin dependencies and function references for the plugin.

Account Kit provides a more robust, easier way to install plugins with pluginActions. Each plugin comes with the its own pluginActions that includes already configured install method, named install<PluginName>, for installing any plugin of interest. For example, MultiOwnerPlugin has multiOwnerPluginActions that includes installMultiOwnerPlugin() method, and SessionKeyPlugin has sessionKeyPluginActions that includes installSessionKeyPlugin() method, all exported from the @alchemy/aa-accounts package.

This guide will use the SessionKeyPlugin as an example to show how you can install SessionKeyPlugin easily using the SmartAccountClient extended with sessionKeyPluginActions.

1. Installing the Session Key Plugin

You should first extend the SmartAccountClient connected to a Modular Account with sessionKeyPluginActions.

Then, you can use the installSessionKeyPlugin() method exposed on sessionKeyPluginActions extended smart account client to install the session key plugin for the connected account.

Note

When using createModularAccountAlchemyClient in @alchemy/aa-alchemy, the SmartAccountClient comes automatically extended with multiOwnerPluginActions, pluginManagerActions, and accountLoupeActions decorators as defaults available for use.

ts
import { smartAccountClient as modularAccountClient } from "./smartAccountClient";
import { sessionKeyPluginActions } from "@alchemy/aa-accounts";


// extend smart account client with sessionKeyPluginActions to call SessionKeyPlugin methods
const sessionKeyExtendedClient = modularAccountClient.extend(
  sessionKeyExtendedClient
);

const { hash } = await sessionKeyExtendedClient.installSessionKeyPlugin({
  // 1st arg is the initial set of session keys
  // 2nd arg is the tags for the session keys
  // 3rd arg is the initial set of permissions
  args: [[], [], []],
});

await client.waitForUserOperationTransaction({ hash });
ts
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, sepolia } from "@alchemy/aa-core";

export const chain = sepolia;

export const smartAccountClient = await createModularAccountAlchemyClient({
  apiKey: "YOUR_API_KEY",
  chain,
  // you can swap this out for any SmartAccountSigner
  signer: LocalAccountSigner.mnemonicToAccountSigner("OWNER_MNEMONIC"),
});

Refer to the Session Key section to learn more about using the SessionKeyPlugin.

2. Uninstalling the Session Key Plugin

On the other hand, uninstalling plugins usually does not involve configuring contract dependencies or function references. You can use the pluginManagerActions's generic uninstallPlugin method to uninstall a particular plugin of interest. First, extend the SmartAccountClient connected to a Modular Account with pluginManagerActions.

Then, you can use the uninstallPlugin() method exposed on pluginManagerActions extended smart account client to uninstall the session key plugin for the connected account.

ts
import {
  chain,
  smartAccountClient as modularAccountClient,
} from "./smartAccountClient";
import { pluginManagerActions, SessionKeyPlugin } from "@alchemy/aa-accounts";


// extend smart account client with pluginManagerActions to call PluginManager action methods
const pluginManagerExtendedClient =
  modularAccountClient.extend(pluginManagerActions);

const { hash } = await pluginManagerExtendedClient.uninstallPlugin({
  pluginAddress: SessionKeyPlugin.meta.addresses[chain.id],
});

await client.waitForUserOperationTransaction({ hash });
ts
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, sepolia } from "@alchemy/aa-core";

export const chain = sepolia;

export const smartAccountClient = await createModularAccountAlchemyClient({
  apiKey: "YOUR_API_KEY",
  chain,
  // you can swap this out for any SmartAccountSigner
  signer: LocalAccountSigner.mnemonicToAccountSigner("OWNER_MNEMONIC"),
});