How It Works
The SDK automatically handles HTTP 402 responses internally. When you pass a payment callback as the second parameter tostore(), the SDK:
- Attempts the store operation
- If the server returns 402 (payment required), the SDK invokes your callback with the payment quote
- Your callback executes the blockchain payment and returns
{ txHash, network } - The SDK automatically retries the store operation with the payment proof
Store with Payment Callback
Store Without Payment Callback
If Auto-Pay is enabled (userKey with authz), no callback needed:Wait for Confirmation
ThewaitForConfirmation option ensures data is confirmed on-chain before returning:
Payment Methods
OnchainDB supports multiple payment methods:Method 1: x402 Payment Callback (Recommended)
Method 2: Auto-Pay
Method 3: Pre-paid with payment_tx_hash
Method 4: Signed Transaction
Browser CORS Considerations
When using the SDK in a browser, blockchain RPC/REST endpoints don’t include CORS headers. You must create server-side API routes to proxy these requests:Keplr Wallet Integration
When integrating with Keplr wallet for payments:Append-Only Storage
OnchainDB uses append-only storage on a Data Availability layer:| Operation | Behavior |
|---|---|
| Create | Appends a new record to the blockchain with a unique ID and timestamp |
| Read | Queries return the latest version of records by default (based on timestamp) |
| Update | Does NOT modify existing data. Instead, appends a NEW record with the same ID but a newer timestamp |
| Delete | Performs a soft delete by appending a new record with deleted: true |
- Complete audit trail - all historical versions are preserved on-chain
- Immutable history - past states cannot be altered
- Blockchain verifiability - every change is recorded on-chain