snap_manageState
Description
Allow the Snap to persist up to 64 MB of data to disk and retrieve it at
will. By default, the data is automatically encrypted using a Snap-specific
key and automatically decrypted when retrieved. You can set encrypted to
false to use unencrypted storage (available when the client is locked).
Parameters
An object containing the parameters for the snap_manageState method.
Options
The clear operation, which deletes all stored state.
operation
"clear"The literal string "clear" to indicate that this is a clear operation.
or
The get operation, which retrieves the stored state.
operation
"get"The literal string "get" to indicate that this is a get operation.
or
The update operation, which replaces the stored state with a new value.
operation
"update"The literal string "update" to indicate that this is an update operation.
newState
Record<string, JSON>The new state to store. Must be a JSON-serializable object.
Common properties
encrypted
booleanWhether to use the encrypted or unencrypted state. Defaults to true
(encrypted). Encrypted state is only accessible when the wallet is
unlocked, while unencrypted state is accessible whether the wallet is
locked or unlocked. State can be cleared regardless of the wallet's lock
state, but this parameter determines which state is cleared.
Returns
If the operation is get, the result is the state. Otherwise, the result is
null.
Example
- Manifest
- Usage
{
"initialPermissions": {
"snap_manageState": {}
}
}
// Persist some data.
await snap.request({
method: "snap_manageState",
params: {
operation: "update",
newState: { hello: "world" },
},
});
// At a later time, get the stored data.
const persistedData = await snap.request({
method: "snap_manageState",
params: { operation: "get" },
});
console.log(persistedData);
// { hello: 'world' }
// If there's no need to store data anymore, clear it out.
await snap.request({
method: "snap_manageState",
params: {
operation: "clear",
},
});