Skip to content

installModule

Installs a ERC-7579 module to the smart account. Check out this guide for a complete tutorial.

Usage

Create a smart account client with one of the following accounts that support ERC-7579:

Kernel Account
import { publicClient } from "../publicClient"
import { createSmartAccountClient } from "permissionless"
import { sepolia } from "viem/chains"
import { http } from "viem"
import { entryPoint07Address } from "viem/account-abstraction"
import { createPimlicoClient } from "permissionless/clients/pimlico"
import { erc7579Actions } from "permissionless/actions/erc7579"
import { owner } from "../owner"
import { toEcdsaKernelSmartAccount } from "permissionless/accounts"
 
const apiKey = "YOUR_PIMLICO_API_KEY"
const pimlicoUrl = `https://api.pimlico.io/v2/sepolia/rpc?apikey=${apiKey}`
 
const pimlicoClient = createPimlicoClient({
	transport: http(pimlicoUrl),
	chain: sepolia,
	entryPoint: {
		address: entryPoint07Address,
		version: "0.7",
	},
})
 
const kernelAccount = await toEcdsaKernelSmartAccount({
	client: publicClient,
	owners: [owner],
	version: "0.3.1",
})
 
// Extend the client with the ERC7579 actions
const smartAccountClient = createSmartAccountClient({
	account: kernelAccount,
	chain: sepolia,
	bundlerTransport: http(pimlicoUrl),
	paymaster: pimlicoClient,
	userOperation: {
		estimateFeesPerGas: async () => {
			return (await pimlicoClient.getUserOperationGasPrice()).fast
		},
	},
}).extend(erc7579Actions())

Use the installModule method to install a module to the smart account.

const ownableExecutorModule = "0xc98B026383885F41d9a995f85FC480E9bb8bB891"
const moduleData = encodePacked(["address"], ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"])
const userOpHash = await smartAccountClient.installModule({
	type: "executor",
	address: ownableExecutorModule,
	context: moduleData,
})
 
const receipt = await smartAccountClient.waitForUserOperationReceipt({ hash: userOpHash })

Returns

  • Type: hash

The user operation hash.

Parameters

address

  • Type: Address

Address of the module to install.

type

  • Type: ModuleType

Type of the module to install. Accepted values are "validator" | "executor" | "fallback" | "hook".

context

  • Type: Hex

Context bytes that will be passed to the module as part of initData.

maxFeePerGas (optional)

  • Type: bigint

The maximum fee per gas that the user is willing to pay for this user operation. If not provided, the bundler will use its own recommendation.

maxPriorityFeePerGas (optional)

  • Type: bigint

The maximum priority fee per gas that the user is willing to pay for this user operation. If not provided, the bundler will use its own recommendation.

nonce (optional)

  • Type: bigint

The nonce of the smart account that will be used to send this user operatino. If not provided, current nonce will be used.