> For the complete documentation index, see [llms.txt](/llms.txt).

- Snap

# snap_setState

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).

If the key is `undefined`, the value is expected to be an object. In this case, the value is set as the new root state.

If the key is not `undefined`, the value is set in the state at the key. If the key does not exist, it is created (and any missing intermediate keys are created as well).

## Parameters[​](#parameters "Direct link to Parameters")

object

required

The request parameters for the `snap_setState` method.

### key

string

The key of the state to update. If not provided, the entire state is updated. This may contain Lodash-style path syntax, for example, `a.b.c`, with the exception of array syntax.

### value

JSON

required

The value to set the state to.

### encrypted

boolean

Whether to use the separate encrypted state, or the unencrypted state. Defaults to the encrypted state. Encrypted state can only be used if the client is unlocked, while unencrypted state can be used whether the client is locked or unlocked.

Use the encrypted state for sensitive data (such as private keys or secrets), and the unencrypted state for non-sensitive data that needs to be accessed while the client is locked.

## Returns[​](#returns "Direct link to Returns")

null

This method does not return any data, so the result is always `null`.

## Example

- Manifest
- Usage

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

```

```
// Set the entire state:
await snap.request({
  method: 'snap_setState',
  params: {
    value: {
      some: {
        nested: {
          value: 'Hello, world!',
        },
      },
    },
    encrypted: true, // Optional, defaults to `true`
  },
})

// Set a specific value within the state:
await snap.request({
  method: 'snap_setState',
  params: {
    key: 'some.nested.value',
    value: 'Hello, world!',
    encrypted: true, // Optional, defaults to `true`
  },
})

```
