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.
Parameter Type EVM Substrate Description item_type string
Required Required Key used to categorize or identify the item. Max 64 bytes. item object
Required Required Value to store. Automatically JSON-serialized if not a string. Max 256 bytes.
Add Item Code Examples
EVM Unsigned Tx
EVM Unsigned Tx Response
EVM Write Tx
EVM Write Response
Substrate Unsigned Call
Substrate Unsigned Call Response
Substrate Write Call
Substrate Write Response
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.
Parameter Type EVM Substrate Description item_type string
Required Required Key used to search for the stored item. address string
Required* Required* Address of the wallet that owns the stored item.
* The address is required when no seed is set.
Get Item Code Examples
EVM No Key Read
EVM No Key Response
EVM Key Read
EVM Key Response
Substrate No Key Read
Substrate No Key Response
Substrate Key Read
Substrate Key Response
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.
Parameter Type EVM Substrate Description item_type string
Required Required Key of the existing item to update. item object
Required Required New value to store. Automatically JSON-serialized if not a string.
Update Item Code Examples
EVM Unsigned Tx
EVM Unsigned Tx Response
EVM Write Tx
EVM Write Response
Substrate Unsigned Call
Substrate Unsigned Call Response
Substrate Write Call
Substrate Write Response
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.
Parameter Type EVM Substrate Description item_type string
Required Required The key representing the pair to be removed.
Remove Item Code Examples
EVM Unsigned Tx
EVM Unsigned Tx Response
EVM Write Tx
EVM Write Response
Substrate Unsigned Call
Substrate Unsigned Call Response
Substrate Write Call
Substrate Write Response
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)