-
Notifications
You must be signed in to change notification settings - Fork 147
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
howydev
wants to merge
1
commit into
howy/add-session-key-docs
Choose a base branch
from
howy/add-transfer-ownership
base: howy/add-session-key-docs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
site/pages/smart-contracts/modular-account-v2/managing-ownership.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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], | ||
}), | ||
}, | ||
}); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!