Storage Programs API Reference
Warning: Storage Programs are still being developed; this documentation is a preview and might not work correctly.Complete API reference for Storage Programs on Demos Network.
Table of Contents
- SDK Methods
- RPC Endpoints
- Transaction Payloads
- Response Formats
- Constants and Limits
- Types and Interfaces
- Error Codes
SDK Methods
DemosClient.storageProgram
ThestorageProgram namespace provides all Storage Program operations.
create()
Create a new Storage Program.Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
programName | string | ✅ | Unique name for the storage program |
accessControl | AccessControlMode | ✅ | Access control mode |
options.initialData | Record<string, any> | ❌ | Initial data to store |
options.allowedAddresses | string[] | ❌ | Whitelist for restricted mode |
options.salt | string | ❌ | Salt for address derivation (default: "") |
Returns
Example
Errors
- 400: Invalid access control mode
- 400: Data size exceeds 128KB limit
- 400: Nesting depth exceeds 64 levels
- 400: Key length exceeds 256 characters
- 400: Restricted mode without allowedAddresses
write()
Write or update data in a Storage Program.Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
storageAddress | string | ✅ | Storage Program address (stor-…) |
data | Record<string, any> | ✅ | Data to write/merge |
Returns
Behavior
- Merges with existing data (does not replace)
- Updates
lastModifiedtimestamp - Recalculates
sizemetadata
Example
Errors
- 403: Access denied (not deployer or allowed)
- 400: Combined size exceeds 128KB limit
- 404: Storage program not found
read()
Read data from a Storage Program (RPC query, no transaction).Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
storageAddress | string | ✅ | Storage Program address |
key | string | ❌ | Specific key to read (optional) |
Returns
Example
Errors
- 403: Access denied
- 404: Storage program not found
updateAccessControl()
Update access control settings (deployer only).Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
storageAddress | string | ✅ | Storage Program address |
updates.accessControl | AccessControlMode | ❌ | New access mode |
updates.allowedAddresses | string[] | ❌ | New whitelist |
Returns
Example
Errors
- 403: Only deployer can update access control
- 400: Restricted mode requires allowedAddresses
delete()
Delete a Storage Program (deployer only).Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
storageAddress | string | ✅ | Storage Program address |
Returns
Example
Errors
- 403: Only deployer can delete
Utility Functions
deriveStorageAddress()
Calculate storage address client-side.Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
deployerAddress | string | ✅ | Deployer’s wallet address |
programName | string | ✅ | Program name |
salt | string | ❌ | Optional salt (default: "") |
Returns
string - Storage address in format stor-{40 hex chars}
Example
getDataSize()
Calculate data size in bytes.Signature
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | Record<string, any> | ✅ | Data object to measure |
Returns
number - Size in bytes (UTF-8 encoded JSON)
Example
RPC Endpoints
getStorageProgram
Query Storage Program data via RPC.Endpoint
POST /rpc
Request Payload
Response
Error Responses
400 - Missing Parameter:Transaction Payloads
CREATE_STORAGE_PROGRAM
WRITE_STORAGE
UPDATE_ACCESS_CONTROL
DELETE_STORAGE_PROGRAM
Response Formats
Success Response
Error Response
Constants and Limits
Storage Limits
Access Control Modes
Address Format
- Prefix:
stor- - Hash: 40 hex characters (SHA256)
- Total Length: 45 characters
- Pattern:
/^stor-[a-f0-9]{40}$/
Types and Interfaces
StorageProgramPayload
StorageProgramMetadata
StorageProgramData
GCREdit
Error Codes
HTTP Status Codes
| Code | Meaning | Description |
|---|---|---|
| 200 | Success | Operation completed successfully |
| 400 | Bad Request | Invalid parameters or validation failed |
| 403 | Forbidden | Access denied |
| 404 | Not Found | Storage program doesn’t exist |
| 500 | Server Error | Internal error or database failure |
Common Error Messages
Validation Errors
Access Control Errors
Operation Errors
Usage Examples
Complete Transaction Flow
Error Handling Pattern
Best Practices
1. Address Derivation
Always derive addresses client-side before creating:2. Size Validation
Check size before operations:3. Access Control
Start restrictive, expand as needed:4. Read Operations
Use specific key reads when possible:5. Error Handling
Always handle errors gracefully:Feature Summary
- Initial Storage Programs implementation
- CREATE, WRITE, READ, UPDATE_ACCESS_CONTROL, DELETE operations
- Four access control modes
- 128KB size limit
- 64 level nesting depth
- 256 character key names