# snap_setState

> Reference documentation for the `snap_setState` method of the Snaps API.

<SnapsAPIReference method={{"name":"snap_setState","description":"Allow the Snap to persist up to 64 MB of data to disk and retrieve it at\nwill. By default, the data is automatically encrypted using a Snap-specific\nkey and automatically decrypted when retrieved. You can set `encrypted` to\n`false` to use unencrypted storage (available when the client is locked).\n\nIf the key is `undefined`, the value is expected to be an object. In this\ncase, the value is set as the new root state.\n\nIf the key is not `undefined`, the value is set in the state at the key. If\nthe key does not exist, it is created (and any missing intermediate keys are\ncreated as well).","parameters":{"kind":"object","type":"{ key?: string | null; value: JSON; encrypted?: boolean | null }","description":"The request parameters for the `snap_setState` method.","required":true,"properties":[{"kind":"primitive","type":"string","description":"The key of the state to update. If not provided, the entire\nstate is updated. This may contain Lodash-style path syntax, for example,\n`a.b.c`, with the exception of array syntax.","name":"key","required":false},{"kind":"primitive","type":"JSON","description":"The value to set the state to.","name":"value","required":true},{"kind":"primitive","type":"boolean","description":"Whether to use the separate encrypted state, or the\nunencrypted state. Defaults to the encrypted state. Encrypted state can only\nbe used if the client is unlocked, while unencrypted state can be used\nwhether the client is locked or unlocked.\n\nUse the encrypted state for sensitive data (such as private keys or secrets),\nand the unencrypted state for non-sensitive data that needs to be accessed\nwhile the client is locked.","name":"encrypted","required":false}]},"result":{"kind":"primitive","type":"null","description":"This method does not return any data, so the result is always `null`."},"subjectTypes":["snap"],"examples":[{"examples":[{"name":"Manifest","language":"json","content":"{\n  \"initialPermissions\": {\n    \"snap_manageState\": {}\n  }\n}\n"},{"name":"Usage","language":"ts","content":"// Set the entire state:\nawait snap.request({\n  method: 'snap_setState',\n  params: {\n    value: {\n      some: {\n        nested: {\n          value: 'Hello, world!',\n        },\n      },\n    },\n    encrypted: true, // Optional, defaults to `true`\n  },\n})\n\n// Set a specific value within the state:\nawait snap.request({\n  method: 'snap_setState',\n  params: {\n    key: 'some.nested.value',\n    value: 'Hello, world!',\n    encrypted: true, // Optional, defaults to `true`\n  },\n})\n"}]}],"restricted":false}}  />
