> For the complete documentation index, see [llms.txt](https://docs.zama.org/protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/protocol/sdk/api-references/sdk/genericstorage.md).

# GenericStorage

Interface for async key-value storage used to persist transport key pairs and signed permits. The SDK ships with four built-in implementations -- you only need this interface if building a custom backend.

## Import

```ts
import type { GenericStorage } from "@zama-fhe/sdk";
```

## Definition

```ts
interface GenericStorage {
  get<T = unknown>(key: string): Promise<T | null>;
  set<T = unknown>(key: string, value: T): Promise<void>;
  delete(key: string): Promise<void>;
}
```

## Usage

```ts
import { ZamaSDK } from "@zama-fhe/sdk";
import type { GenericStorage } from "@zama-fhe/sdk";

const redisStorage: GenericStorage = {
  async get(key) {
    return redis.get(key);
  },
  async set(key, value) {
    await redis.set(key, value);
  },
  async delete(key) {
    await redis.del(key);
  },
};

const config = createConfig({
  chains: [sepolia],
  signer: mySigner,
  provider: myProvider,
  storage: redisStorage,
  relayers: { [sepolia.id]: node() },
});
const sdk = new ZamaSDK(config);
```

## Methods

### get

```ts
get<T = unknown>(key: string): Promise<T | null>
```

Retrieve a value by key. Return `null` if the key does not exist. The generic `T` allows typed reads.

### set

```ts
set<T = unknown>(key: string, value: T): Promise<void>
```

Store a value under the given key. Overwrites any existing value. Accepts any serializable type.

### delete

```ts
delete(key: string): Promise<void>
```

Remove a key and its value. No-op if the key does not exist.

## Built-in implementations

### indexedDBStorage

```ts
import { indexedDBStorage } from "@zama-fhe/sdk";
```

Browser-based persistent storage backed by IndexedDB. Survives page reloads and browser restarts. Use this as the primary `storage` in browser apps.

```ts
const sdk = new ZamaSDK(config); // config from createConfig()
```

### memoryStorage

```ts
import { memoryStorage } from "@zama-fhe/sdk";
```

In-memory storage cleared when the process exits. Suitable for tests and throwaway scripts.

```ts
const sdk = new ZamaSDK(config); // config from createConfig()
```

### asyncLocalStorage

```ts
import { asyncLocalStorage } from "@zama-fhe/sdk/node";
```

Node.js per-request storage using [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html). Isolates transport key pairs across concurrent requests on a server.

```ts
import { asyncLocalStorage } from "@zama-fhe/sdk/node";

app.post("/api/transfer", (req, res) => {
  asyncLocalStorage.run(async () => {
    const config = createConfig({
      chains: [mySepolia],
      signer: wallet,
      storage: asyncLocalStorage,
      relayers: { [mySepolia.id]: node() },
    });
    const sdk = new ZamaSDK(config);
    await sdk.createToken("0x...").confidentialTransfer("0x...", 100n);
  });
});
```

### chromeSessionStorage

```ts
import { chromeSessionStorage } from "@zama-fhe/sdk";
```

MV3 web extension storage backed by `chrome.storage.session`. Survives service worker restarts and is shared across popup, background, and content script contexts. Cleared when the browser closes.

Pass as `permitStorage` (not `storage`) to persist signed permits across service worker restarts:

```ts
const config = createConfig({
  chains: [mySepolia],
  publicClient,
  walletClient,
  storage: indexedDBStorage,
  permitStorage: chromeSessionStorage,
  relayers: { [mySepolia.id]: web() },
});
const sdk = new ZamaSDK(config);
```

## Related

* [ZamaSDK](/protocol/sdk/api-references/sdk/zamasdk.md) -- accepts `storage` and `permitStorage` parameters
* [Configuration guide](/protocol/sdk/guides/configuration.md) -- storage selection guidance


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zama.org/protocol/sdk/api-references/sdk/genericstorage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
