Skip to content

installModule

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

Usage

example.ts
import { erc7579Actions } from "permissionless/actions/erc7579"
 
const safeAccount = await signerToSafeSmartAccount(publicClient, {
	signer,
	safeVersion: "1.4.1",
	entryPoint: ENTRYPOINT_ADDRESS_V07,
	safe4337ModuleAddress: "0x3Fdb5BC686e861480ef99A6E3FaAe03c0b9F32e2", // These are not meant to be used in production as of now.
	erc7579LaunchpadAddress: "0xEBe001b3D534B9B6E2500FB78E67a1A137f561CE", // These are not meant to be used in production as of now.
})
 
// Extend the client with the ERC7579 actions
const smartAccountClient = createSmartAccountClient({
	account: safeAccount,
	entryPoint: ENTRYPOINT_ADDRESS_V07,
	chain: sepolia,
	bundlerTransport: http(bundlerUrl),
	middleware: {
		gasPrice: async () => {
			return (await pimlicoBundlerClient.getUserOperationGasPrice()).fast
		},
		sponsorUserOperation: pimlicoBundlerClient.sponsorUserOperation,
	},
}).extend(erc7579Actions({ entryPoint: ENTRYPOINT_ADDRESS_V07 }))
 
const ownableExecutorModule = "0xc98B026383885F41d9a995f85FC480E9bb8bB891"
 
const moduleData = encodePacked(["address"], ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"])
const userOpHash = await smartAccountClient.installModule({
	type: "executor",
	address: ownableExecutorModule,
	context: moduleData,
})
 
const receipt = await pimlicoBundlerClient.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.