Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add transfer ownership guides for ma v2 #1400

Open
wants to merge 1 commit into
base: howy/add-session-key-docs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Managing ownership
description: Managing ownership on your Modular Account V2
---

# Managing Ownership
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, but reading this as someone who didn't know how to do this already left me
wondering if I could call updateFallbackSignerData with some address, then call it again with an additional address, will it keep adding additional owners?

I looked at the contract code and saw that there is only a single fallback signer address, so calling it additional times will just update/replace it. But might be good to mention that here?

Also it's a little unclear to me whether calling this is transferring ownership (removing the original owner) or if the "fallback signer" is a separate thing that is just for an additional signer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout, updated to make it more clear!


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](/smart-contracts/modular-account-v2/session-keys/adding-session-keys).

```ts twoslash
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],
}),
},
});
```
4 changes: 4 additions & 0 deletions site/sidebar/smart-contracts.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.