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
operation
"clear" | "get" | "update"requiredThe operation to perform on the state.
encrypted
boolean | nullWhether to use the separate encrypted state, or the unencrypted state. Defaults to the encrypted state.
Returns
Record<string, Json> | null
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",
},
});