Skip to content

Managing Ownership

You can add an owner to your account, or transfer ownership of your account with Modular Account V2.

To transfer ownership, we call the updateFallbackSignerData function. Modular Account V2s achieve huge savings on creation because we cache the owner address in immutable bytecode on account creation. When transferring ownership, we set the fallback signer to the new owner address and this will be used during validation. We set the boolean to false for the account to check this value in storage instead of the immutable cached owner address.

Note that updateFallbackSignerData is an ownership transfer operation, and the previous owner would lose access to the account. To add an owner, you should add a session key with root permissions instead.

import { createModularAccountV2Client } from "@account-kit/smart-contracts";
import { semiModularAccountBytecodeAbi } from "@account-kit/smart-contracts/experimental";
import { type SmartAccountSigner, LocalAccountSigner } from "@aa-sdk/core";
import { generatePrivateKey } from "viem/accounts";
import { encodeFunctionData } from "viem";
import { sepolia, alchemy } from "@account-kit/infra";
 
const client = await createModularAccountV2Client({
  chain: sepolia,
  transport: alchemy({ apiKey: "your-api-key" }),
  signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey()),
});
 
const newOwner = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
 
// The boolean parameter in updateFallbackSignerData is `isFallbackSignerDisabled`, and false indicates that we are using the value of the fallback signer
await client.sendUserOperation({
  uo: {
    target: client.account.address,
    value: 0n,
    data: encodeFunctionData({
      abi: semiModularAccountBytecodeAbi,
      functionName: "updateFallbackSignerData",
      args: [newOwner, false],
    }),
  },
});