SnapController Actions
26 actions registered.
SnapController:clearSnapState
Package: @metamask/snaps-controllers
Clears the state of the snap with the given id. This is distinct from the state MetaMask uses to manage snaps.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap whose state should be cleared. |
encrypted | A flag to indicate whether to use encrypted storage or not. |
Handler signature:
(snapId: SnapId, encrypted: boolean) => void
SnapController:clearState
Package: @metamask/snaps-controllers
Completely clear the controller's state: delete all associated data, handlers, event listeners, and permissions; tear down all snap providers. Also re-initializes the controller after clearing the state.
Handler signature:
() => Promise<void>
SnapController:disableSnap
Package: @metamask/snaps-controllers
Disables the given snap. A snap can only be started if it is enabled.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to disable. |
Returns: A promise that resolves once the snap has been disabled.
Handler signature:
(snapId: SnapId) => Promise<void>
SnapController:disconnectOrigin
Package: @metamask/snaps-controllers
Disconnect the Snap from the given origin, meaning the origin can no longer interact with the Snap until it is reconnected.
Parameters:
| Name | Description |
|---|---|
origin | The origin from which to remove the Snap. |
snapId | The id of the snap to remove. |
Handler signature:
(origin: string, snapId: SnapId) => void
SnapController:enableSnap
Package: @metamask/snaps-controllers
Enables the given snap. A snap can only be started if it is enabled. A snap can only be enabled if it isn't blocked.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to enable. |
Handler signature:
(snapId: SnapId) => void
SnapController:getAllSnaps
Package: @metamask/snaps-controllers
Gets all snaps in their truncated format.
Returns: All installed snaps in their truncated format.
Handler signature:
() => TruncatedSnap[]
SnapController:getPermittedSnaps
Package: @metamask/snaps-controllers
Gets the serialized permitted snaps of the given origin, if any.
Parameters:
| Name | Description |
|---|---|
origin | The origin whose permitted snaps to retrieve. |
Returns: The serialized permitted snaps for the origin.
Handler signature:
(origin: string) => RequestSnapsResult
SnapController:getRunnableSnaps
Package: @metamask/snaps-controllers
Gets all runnable snaps.
Returns: All runnable snaps.
Handler signature:
() => TruncatedSnap[]
SnapController:getSnap
Package: @metamask/snaps-controllers
Gets the snap with the given id if it exists, including all data. This should not be used if the snap is to be serializable, as e.g. the snap sourceCode may be quite large.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to get. |
Returns: The entire snap object from the controller state.
Handler signature:
(snapId: string) => Snap | null
SnapController:getSnapFile
Package: @metamask/snaps-controllers
Gets a static auxiliary snap file in a chosen file encoding.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap whose state to get. |
path | The path to the requested file. |
encoding | An optional requested file encoding. |
Returns: The file requested in the chosen file encoding or null if the file is not found.
Handler signature:
(snapId: SnapId, path: string, encoding?: AuxiliaryFileEncoding) => Promise<string | null>
SnapController:getSnapState
Package: @metamask/snaps-controllers
Gets the own state of the snap with the given id. This is distinct from the state MetaMask uses to manage snaps.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap whose state to get. |
encrypted | A flag to indicate whether to use encrypted storage or not. |
Returns: The requested snap state or null if no state exists.
Handler signature:
(snapId: SnapId, encrypted: boolean) => Promise<Json>
SnapController:getState
Package: @metamask/snaps-controllers
Handler signature:
() => SnapControllerState
SnapController:handleRequest
Package: @metamask/snaps-controllers
Passes a JSON-RPC request object to the RPC handler function of a snap.
Parameters:
| Name | Description |
|---|---|
options | A bag of options. |
options.snapId | The ID of the recipient snap. |
options.origin | The origin of the RPC request. |
options.originMetadata | Optional additional origin metadata for the RPC request. |
options.handler | The handler to trigger on the snap for the request. |
options.request | The JSON-RPC request object. |
Returns: The result of the JSON-RPC request.
Handler signature:
({ snapId, origin, originMetadata, handler: handlerType, request: rawRequest, }: SnapRpcHookArgs & {
snapId: SnapId;
}) => Promise<unknown>
SnapController:hasSnap
Package: @metamask/snaps-controllers
Returns whether the given snap has been added to state.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to check for. |
Returns: true if the snap exists in the controller state, otherwise false.
Handler signature:
(snapId: SnapId) => boolean
SnapController:init
Package: @metamask/snaps-controllers
Initialise the SnapController.
Currently this method sets up the controller and calls the onStart lifecycle hook for all
runnable Snaps.
Parameters:
| Name | Description |
|---|---|
waitForPlatform | Whether to wait for the platform to be ready before returning. |
Handler signature:
(waitForPlatform?: boolean) => Promise<void>
SnapController:installSnaps
Package: @metamask/snaps-controllers
Installs the snaps requested by the given origin, returning the snap object if the origin is permitted to install it, and an authorization error otherwise.
Parameters:
| Name | Description |
|---|---|
origin | The origin that requested to install the snaps. |
requestedSnaps | The snaps to install. |
Returns: An object of snap ids and snap objects, or errors if a snap couldn't be installed.
Handler signature:
(origin: string, requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>
SnapController:isMinimumPlatformVersion
Package: @metamask/snaps-controllers
Determine if a given Snap ID supports a given minimum version of the Snaps platform by inspecting the platformVersion in the Snap manifest.
Parameters:
| Name | Description |
|---|---|
snapId | The Snap ID. |
version | The version. |
Returns: True if the platform version is equal or greater to the passed version, false otherwise.
Handler signature:
(snapId: SnapId, version: SemVerVersion) => boolean
SnapController:isSnapRunning
Package: @metamask/snaps-controllers
Returns whether the given snap is running. Throws an error if the snap doesn't exist.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to check. |
Returns: true if the snap is running, otherwise false.
Handler signature:
(snapId: SnapId) => boolean
SnapController:removeSnap
Package: @metamask/snaps-controllers
Removes the given snap from state, and clears all associated handlers and listeners.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap. |
Returns: A promise that resolves once the snap has been removed.
Handler signature:
(snapId: SnapId) => Promise<void>
SnapController:removeSnaps
Package: @metamask/snaps-controllers
Stops the given snaps, removes them from state, and clears all associated permissions, handlers, and listeners.
Parameters:
| Name | Description |
|---|---|
snapIds | The ids of the Snaps. |
Handler signature:
(snapIds: SnapId[]) => Promise<void>
SnapController:revokeDynamicSnapPermissions
Package: @metamask/snaps-controllers
Checks if a list of permissions are dynamic and allowed to be revoked, if they are they will all be revoked.
Parameters:
| Name | Description |
|---|---|
snapId | The snap ID. |
permissionNames | The names of the permissions. |
Handler signature:
(snapId: string, permissionNames: NonEmptyArray<string>) => void
SnapController:setClientActive
Package: @metamask/snaps-controllers
Set the active state of the client. This will trigger the onActive or
onInactive lifecycle hooks for all Snaps.
Parameters:
| Name | Description |
|---|---|
active | A boolean indicating whether the client is active or not. |
Handler signature:
(active: boolean) => void
SnapController:stopAllSnaps
Package: @metamask/snaps-controllers
Stops all running snaps, removes all hooks, closes all connections, and terminates their workers.
Parameters:
| Name | Description |
|---|---|
statusEvent | The Snap status event that caused the snap to be stopped. |
Handler signature:
(statusEvent?: SnapStatusEvents.Stop | SnapStatusEvents.Crash) => Promise<void>
SnapController:stopSnap
Package: @metamask/snaps-controllers
Stops the given snap, removes all hooks, closes all connections, and terminates its worker.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap to stop. |
statusEvent | The Snap status event that caused the snap to be stopped. |
Handler signature:
(snapId: SnapId, statusEvent?: SnapStatusEvents.Stop | SnapStatusEvents.Crash) => Promise<void>
SnapController:updateRegistry
Package: @metamask/snaps-controllers
Trigger an update of the registry.
As a side-effect, this will always check if preinstalled Snaps can be updated and whether any Snaps need to be blocked/unblocked.
Handler signature:
() => Promise<void>
SnapController:updateSnapState
Package: @metamask/snaps-controllers
Updates the own state of the snap with the given id. This is distinct from the state MetaMask uses to manage snaps.
Parameters:
| Name | Description |
|---|---|
snapId | The id of the Snap whose state should be updated. |
newSnapState | The new state of the snap. |
encrypted | A flag to indicate whether to use encrypted storage or not. |
Handler signature:
(snapId: SnapId, newSnapState: Record<string, Json>, encrypted: boolean) => Promise<void>