> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peaq.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Storage Operations

> Store key-value pairs on peaq using the JavaScript SDK. Covers addItem parameters, storage size limits, and EVM and Substrate examples.

peaq provides on-chain storage. Data is saved as a `key: value` pair.

## addItem(itemType, item, seed)

Adds an entry pair to the blockchain.

| Parameter | Type | EVM | Substrate | Description |
| - | - | - | - | - |
| **itemType** | `string` | Required | Required | Key that will be stored in peaq storage. Max 64 bytes. |
| **item** | `object` | Required | Required | Value that will be stored in peaq storage. Max 256 bytes. |
| **seed** | `string` | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |

### Add Item Code Examples

```javascript EVM Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const key = "my_key";
const value = "my_value";

const tx = await sdk.storage.addItem({
    itemType: key,
    item: value
});

const receipt = await Sdk.sendEvmTx({
    tx: tx,
    baseUrl: HTTPS_BASE_URL,
    seed: EVM_PRIVATE
});
```

```javascript EVM Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.addItem({}) return object
{
  to: '0x0000000000000000000000000000000000000801',
  data: '0x257c3c030000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000066d795f6b6579000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086d795f76616c7565000000000000000000000000000000000000000000000000'
}

// sendEvmTx({}) return object
TransactionReceipt {
  provider: JsonRpcProvider {},
  to: '0x0000000000000000000000000000000000000801',
  from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
  contractAddress: null,
  hash: '0x6fec47eadcba1d94e28a6d08b997aa717b69cd3c4319adb7459d21018866602a',
  index: 0,
  blockHash: '0x46a7dae54300988b4fdd42957e033d32219c2f09d683c932f00cd96d312f4f54',
  blockNumber: 4488814,
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000800000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000010000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  gasUsed: 43014n,
  blobGasUsed: null,
  cumulativeGasUsed: 43014n,
  gasPrice: 100000000000n,
  blobGasPrice: null,
  type: 2,
  status: 1,
  root: undefined
}
```

```javascript Substrate Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];

const sdk = await Sdk.createInstance({
    baseUrl: WSS_BASE_URL,
    chainType: Sdk.ChainType.SUBSTRATE,
    seed: SUBSTRATE_SEED
});

const key = "my_key";
const value = "my_value";

const result = await sdk.storage.addItem({
    itemType: key,
    item: value
});

// disconnect when finished
await sdk.disconnect();
```

```javascript Substrate Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.addItem({}) return object
{
  message: 'Successfully added the storage item type my_key with item my_value for the address 5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg',
  block_hash: '0xafe84e572ad2ca33cbdad683dfcf2c8ac65bb9944c34304a81010212973739fa',
  unsubscribe: [Function (anonymous)]
}
```

## getItem(itemType, address, wssBaseUrl)

Returns the `key: value` pair of what is stored on-chain.

| Parameter | Type | EVM | Substrate | Description |
| - | - | - | - | - |
| **itemType** | `string` | Required | Required | Key that will be used to search peaq storage at the address. |
| **address** | `string` | Required | Optional | Wallet address where the key is stored. |
| **wssBaseUrl** | `string` | Required | N/A | WSS URL must be used to read from storage. EVM must explicitly set WSS (Substrate has it stored during creation). |

### Get Item Code Examples

```javascript EVM Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const key = "my_key";
const pair = await sdk.storage.getItem({
    itemType: key,
    address: EVM_ADDRESS,
    wssBaseUrl: WSS_BASE_URL
});
```

```javascript EVM Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.getItem({}) return object
{ my_key: 'my_value' }
```

```javascript Substrate Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];

const sdk = await Sdk.createInstance({
    baseUrl: WSS_BASE_URL,
    chainType: Sdk.ChainType.SUBSTRATE,
    seed: SUBSTRATE_SEED
});

const key = "my_key";
const pair = await sdk.storage.getItem({
    itemType: key
});

// disconnect when finished
await sdk.disconnect();
```

```javascript Substrate Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.getItem({}) return object
{ my_key: 'my_value' }
```

## updateItem(itemType, item, seed)

Updates the value in storage for the key passed.

| Parameter | Type | EVM | Substrate | Description |
| - | - | - | - | - |
| **itemType** | `string` | Required | Required | Key that is stored in peaq storage whose value will be updated. |
| **item** | `object` | Required | Required | New value that will be stored in peaq storage. |
| **seed** | `string` | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |

### Update Item Code Examples

```javascript EVM Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const key = "my_key";
const value = "my_new_value";

const tx = await sdk.storage.updateItem({
    itemType: key,
    item: value
});
const receipt = await Sdk.sendEvmTx({
    tx: tx,
    baseUrl: HTTPS_BASE_URL,
    seed: EVM_PRIVATE
});

// read to see the change
const pair = await sdk.storage.getItem({
    itemType: key,
    address: EVM_ADDRESS,
    wssBaseUrl: WSS_BASE_URL
});
```

```javascript EVM Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.updateItem({}) return object
{
  to: '0x0000000000000000000000000000000000000801',
  data: '0x1cd4bf090000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000066d795f6b65790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c6d795f6e65775f76616c75650000000000000000000000000000000000000000'
}
```

```javascript Substrate Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];

const sdk = await Sdk.createInstance({
    baseUrl: WSS_BASE_URL,
    chainType: Sdk.ChainType.SUBSTRATE,
    seed: SUBSTRATE_SEED
});

const key = "my_key";
const value = "my_new_value";

const response = await sdk.storage.updateItem({
    itemType: key,
    item: value
});

// read to see it has been changed
const pair = await sdk.storage.getItem({
    itemType: key
});
// disconnect when finished
await sdk.disconnect();
```

```javascript Substrate Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.updateItem({}) return object
{
  message: 'Successfully updated the storage item type my_key to the new item my_new_value for the address 5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg',
  block_hash: '0xb75cf6b47421c585772220bd99df1850a50e59ce506d6302eaba49db6e029288',
  unsubscribe: [Function (anonymous)]
}
```

## removeItem(itemType, seed)

Removes the item type and item from peaq storage.

| Parameter | Type | EVM | Substrate | Description |
| - | - | - | - | - |
| **itemType** | `string` | N/A | Required | The key representing the pair to be removed. |
| **seed** | `string` | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |

### Remove Item Code Examples

```javascript Substrate Request theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import { Sdk } from "@peaq-network/sdk";

const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];

const sdk = await Sdk.createInstance({
    baseUrl: WSS_BASE_URL,
    chainType: Sdk.ChainType.SUBSTRATE,
    seed: SUBSTRATE_SEED
});

const key = "my_key";

const response = await sdk.storage.removeItem({
    itemType: key
});

// disconnect when finished
await sdk.disconnect();
```

```javascript Substrate Response theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
// sdk.storage.removeItem({}) return object
{
  message: 'Successfully removed the storage item type my_key from address 5Df42mkztLtkksgQuLy4YV6hmhzdjYvDknoxHv1QBkaY12Pg',
  block_hash: '0xb40d8934dc69c871b8ee36a34ef63ae5fb0b93c06b5d8d5c5df5244e001d3acb',
  unsubscribe: [Function (anonymous)]
}
```

This SDK does not build an EVM `removeItem` transaction. To remove an item over EVM, send a transaction to the storage precompile at `0x0000000000000000000000000000000000000801` calling `removeItem(bytes)` with the UTF-8 bytes of the key, or use a Substrate instance.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.