Socket
Socket
Sign inDemoInstall

@metamask/manage-state-example-snap

Package Overview
Dependencies
165
Maintainers
12
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @metamask/manage-state-example-snap

MetaMask example snap demonstrating the use of `snap_manageState`.


Version published
Weekly downloads
2K
decreased by-31.91%
Maintainers
12
Created
Weekly downloads
 

Readme

Source

@metamask/manage-state-example-snap

This snap demonstrates how to use snap_manageState to store, receive, and clear internal state within a snap. This state is encrypted before being stored on the user's disk, and is the recommended way for storing data in a snap long-term.

Snap manifest

Note: Using snap_manageState requires the snap_manageState permissions. Refer to the documentation for more information.

Along with other permissions, the manifest of this snap includes the snap_manageState permission:

{
  "initialPermissions": {
    "snap_manageState": {}
  }
}

This permission does not require any additional configuration.

Snap usage

The state is stored in the snap using the following structure:

type State = {
  items: string[];
};

This snap exposes an onRpcRequest handler, which supports the following JSON-RPC methods:

  • setState - Set the state to the provided params. This assumes the new state is an object using the above structure, but for simplicity, this is not actually validated within the snap.
  • getState - Get the state from the snap. This returns the current state if one is set, or a default state otherwise.
  • clearState - Reset the state to the default state.

Each of the methods also takes an encrypted parameter. This parameter can be used to choose between using encrypted or unencrypted storage. Encrypted storage requires MetaMask to be unlocked, unencrypted storage does not.

For more information, you can refer to the end-to-end tests.

FAQs

Last updated on 20 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc