Skip to main content

AccountTreeController Actions

23 actions registered.

NameDeprecated
clearState
exportState
getAccountContext
getAccountFromSelectedAccountGroup
getAccountGroupObject
getAccountsFromSelectedAccountGroup
getAccountWalletObject
getAccountWalletObjects
getSelectedAccountGroup
getState
importState
init
isInitialized
reinit
removeAccountWallet
setAccountGroupHidden
setAccountGroupName
setAccountGroupPinned
setAccountWalletName
setSelectedAccountGroup
setSelectedAccountGroupByAccountId
syncWithUserStorage
syncWithUserStorageAtLeastOnce

AccountTreeController:clearState​

Package: @metamask/account-tree-controller

Clears the controller state and resets to default values. Also clears the backup and sync service state.

Handler signature:

() => void

AccountTreeController:exportState​

Package: @metamask/account-tree-controller

Produces a versioned snapshot of the current wallet and group state.

When options.includeSecrets is true, options.password is required and verified against the vault before any secret is read. Without includeSecrets, only metadata (names, pinned, hidden) is exported and no password is needed.

Parameters:

NameDescription
optionsExport options.

Returns: A promise resolving to an AccountTreeSnapshot.

Handler signature:

(options?: ExportStateOptions) => Promise<AccountTreeSnapshot>

AccountTreeController:getAccountContext​

Package: @metamask/account-tree-controller

Gets the account's context which contains its wallet ID, group ID, and sort order.

Parameters:

NameDescription
accountIdAccount ID.

Returns: The account context if found, undefined otherwise.

Handler signature:

(accountId: AccountId) => AccountContext | undefined

AccountTreeController:getAccountFromSelectedAccountGroup​

Package: @metamask/account-tree-controller

Gets an account from the currently selected account group, optionally filtered by a CAIP-2 chain ID.

This is the group-based replacement for both AccountsController:getSelectedAccount and AccountsController:getSelectedMultichainAccount.

When no chain ID is provided, an account of the selected group is returned using an EVM-priority rule: the first EVM account found in the group, or the first account in the group if no EVM account is found. When a chain ID is provided, the first account in the selected group whose scopes match the given chain is returned.

Parameters:

NameDescription
chainIdOptional CAIP-2 chain ID used to filter accounts by scope.

Returns: The matching internal account from the selected group, or undefined if no group is selected or no account matches.

Handler signature:

(chainId?: CaipChainId) => InternalAccount | undefined

AccountTreeController:getAccountGroupObject​

Package: @metamask/account-tree-controller

Gets the account group object from its ID.

Parameters:

NameDescription
groupIdAccount group ID.

Returns: The account group object if found, undefined otherwise.

Handler signature:

(groupId: AccountGroupId) => AccountGroupObject | undefined

AccountTreeController:getAccountsFromSelectedAccountGroup​

Package: @metamask/account-tree-controller

Gets all underlying accounts from the currently selected account group.

It also support account selector, which allows to filter specific accounts given some criterias (account type, address, scopes, etc...).

Parameters:

NameDescription
selectorOptional account selector.

Returns: Underlying accounts for the currently selected account (filtered by the selector if provided).

Handler signature:

(selector?: AccountSelector<InternalAccount>) => InternalAccount[]

AccountTreeController:getAccountWalletObject​

Package: @metamask/account-tree-controller

Gets the account wallet object from its ID.

Parameters:

NameDescription
walletIdAccount wallet ID.

Returns: The account wallet object if found, undefined otherwise.

Handler signature:

(walletId: AccountWalletId) => AccountWalletObject | undefined

AccountTreeController:getAccountWalletObjects​

Package: @metamask/account-tree-controller

Gets all account wallet objects.

Returns: All account wallet objects.

Handler signature:

() => AccountWalletObject[]

AccountTreeController:getSelectedAccountGroup​

Package: @metamask/account-tree-controller

Gets the currently selected account group ID.

Returns: The selected account group ID or empty string if none selected.

Handler signature:

() => AccountGroupId | ''

AccountTreeController:getState​

Package: @metamask/account-tree-controller

Handler signature:

() => AccountTreeControllerState

AccountTreeController:importState​

Package: @metamask/account-tree-controller

Applies a validated snapshot to the current state.

Accepts an AccountTreeSnapshot only — untrusted wire data must be parsed with AccountTreeSnapshot.deserialize first. Callers may filter the snapshot with AccountTreeSnapshot.filterWallets, AccountTreeSnapshot.filterGroups, or AccountTreeSnapshot.filterAllGroups before importing.

New mnemonic wallets are imported via MultichainAccountService and new private-key accounts via KeyringController. Metadata (name, pinned, hidden) is applied to all existing and newly created wallets / groups.

Parameters:

NameDescription
snapshotThe validated snapshot to import.

Returns: A promise that resolves when the import is complete.

Handler signature:

(snapshot: AccountTreeSnapshot) => Promise<void>

AccountTreeController:init​

Package: @metamask/account-tree-controller

Initialize the controller's state.

It constructs the initial state of the account tree (tree nodes, nodes names, metadata, etc..) and will automatically update the controller's state with it.

Handler signature:

() => void

AccountTreeController:isInitialized​

Package: @metamask/account-tree-controller

Whether init() has completed and the account tree is ready to consume. Returns false after clearState() until the next successful init().

Returns: True when the controller has been initialized.

Handler signature:

() => boolean

AccountTreeController:reinit​

Package: @metamask/account-tree-controller

Re-initialize the controller's state.

This is done in one single (atomic) update block to avoid having a temporary cleared state. Use this when you need to force a full re-init even if already initialized.

Handler signature:

() => void

AccountTreeController:removeAccountWallet​

Package: @metamask/account-tree-controller

Removes an account wallet and all of its underlying accounts.

The account tree is a derived view of AccountsController state, so this method intentionally does not mutate tree nodes directly. Account removal causes AccountsController to publish accountsRemoved, which lets #handleAccountsRemoved consistently prune tree nodes, reverse mappings, metadata, and selection state.

Parameters:

NameDescription
walletIdAccount wallet ID.

Handler signature:

(walletId: AccountWalletId) => Promise<void>

AccountTreeController:setAccountGroupHidden​

Package: @metamask/account-tree-controller

Toggles the hidden state of an account group.

Parameters:

NameDescription
groupIdThe account group ID.
hiddenWhether the group should be hidden.

Handler signature:

(groupId: AccountGroupId, hidden: boolean) => void

AccountTreeController:setAccountGroupName​

Package: @metamask/account-tree-controller

Sets a custom name for an account group.

Parameters:

NameDescription
groupIdThe account group ID.
nameThe custom name to set.
autoHandleConflictIf true, automatically resolves name conflicts by adding a suffix. If false, throws on conflicts.

Handler signature:

(groupId: AccountGroupId, name: string, autoHandleConflict?: boolean) => void

AccountTreeController:setAccountGroupPinned​

Package: @metamask/account-tree-controller

Toggles the pinned state of an account group.

Parameters:

NameDescription
groupIdThe account group ID.
pinnedWhether the group should be pinned.

Handler signature:

(groupId: AccountGroupId, pinned: boolean) => void

AccountTreeController:setAccountWalletName​

Package: @metamask/account-tree-controller

Sets a custom name for an account wallet.

Parameters:

NameDescription
walletIdThe account wallet ID.
nameThe custom name to set.

Handler signature:

(walletId: AccountWalletId, name: string) => void

AccountTreeController:setSelectedAccountGroup​

Package: @metamask/account-tree-controller

Sets the selected account group and updates the AccountsController selectedAccount accordingly.

Parameters:

NameDescription
groupIdThe account group ID to select.

Handler signature:

(groupId: AccountGroupId) => void

AccountTreeController:setSelectedAccountGroupByAccountId​

Package: @metamask/account-tree-controller

Sets the selected account group and updates the AccountsController selectedAccount accordingly.

Parameters:

NameDescription
accountIdThe account ID to select the group for.

Handler signature:

(accountId: AccountId) => void

AccountTreeController:syncWithUserStorage​

Package: @metamask/account-tree-controller

Bi-directionally syncs the account tree with user storage. This will perform a full sync, including both pulling updates from user storage and pushing local changes to user storage. This also performs legacy account syncing if needed.

IMPORTANT: If a full sync is already in progress, it will return the ongoing promise.

Returns: A promise that resolves when the sync is complete.

Handler signature:

() => Promise<void>

AccountTreeController:syncWithUserStorageAtLeastOnce​

Package: @metamask/account-tree-controller

Bi-directionally syncs the account tree with user storage. This will ensure at least one full sync is ran, including both pulling updates from user storage and pushing local changes to user storage. This also performs legacy account syncing if needed.

IMPORTANT: If the first ever full sync is already in progress, it will return the ongoing promise. If the first ever full sync was previously completed, it will NOT start a new sync, and will resolve immediately.

Returns: A promise that resolves when the first ever full sync is complete.

Handler signature:

() => Promise<void>