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
The request parameters for the snap_manageState method.
Options
The clear state operation, which clears the state.
operation
"clear"The operation to perform on the state. Must be clear.
or
The get state operation, which retrieves the state.
operation
"get"The operation to perform on the state. Must be get.
or
The update state operation, which updates the state.
operation
"update"The operation to perform on the state. Must be
update.
newState
Record<string, Json>The new state to set.
Common properties
encrypted
booleanWhether to use the separate encrypted state, or the unencrypted state. Defaults to the encrypted state. Encrypted state can only be used if the extension is unlocked, while unencrypted state can be used whether the extension is locked or unlocked.
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",
},
});