The peaq network allows you to store on-chain data using a simple key: value structure.

add_item(item_type, item)

Adds a new key-value pair to the on-chain storage. If the item is not already a string, it will be automatically JSON-serialized before storage.

ParameterTypeEVMSubstrateDescription
item_typestringRequiredRequiredKey used to categorize or identify the item. Max 64 bytes.
itemobjectRequiredRequiredValue to store. Automatically JSON-serialized if not a string. Max 256 bytes.

Add Item Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

item_type='my_key'
item='my_value'

response = sdk.storage.add_item(item_type=item_type, item=item)

get_item(item_type, address)

Retrieves a stored item by its key for the specified address. Returns the decoded value as a string.

Cross-chain storage querying:

  • Substrate: Uses the existing Substrate API connection directly to query storage
  • EVM: Automatically uses the SDK’s base_url to create a temporary Substrate connection.
ParameterTypeEVMSubstrateDescription
item_typestringRequiredRequiredKey used to search for the stored item.
addressstringRequired*Required*Address of the wallet that owns the stored item.

* The address is required when no seed is set.

Get Item Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

item_type='my_key'

response = sdk.storage.get_item(item_type=item_type, address=EVM_ADDRESS)

update_item(item_type, item)

Updates an existing item in on-chain storage by replacing its value with a new one. The item will be automatically JSON-serialized if it’s not already a string.

ParameterTypeEVMSubstrateDescription
item_typestringRequiredRequiredKey of the existing item to update.
itemobjectRequiredRequiredNew value to store. Automatically JSON-serialized if not a string.

Update Item Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

item_type='my_key'
item='my_new_value'

response = sdk.storage.update_item(item_type=item_type, item=item)

remove_item(item_type)

Removes an existing key-value pair from on-chain storage.

ParameterTypeEVMSubstrateDescription
item_typestringRequiredRequiredThe key representing the pair to be removed.

Remove Item Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

item_type='my_key'

response = sdk.storage.remove_item(item_type=item_type)