Documentation Index
Fetch the complete documentation index at: https://docs.ondb.ai/llms.txt
Use this file to discover all available pages before exploring further.
store
Store documents in a collection with payment.
const result = await client.store(
{
collection: 'users',
data: [{ email: 'alice@example.com', name: 'Alice', active: true }]
},
async (quote) => {
// quote contains: totalCost, brokerAddress, tokenSymbol, network, chainType
const txHash = await processPayment(quote);
return { txHash, network: quote.network, sender: walletAddress, chainType: quote.chainType, paymentMethod: 'native' };
},
true // waitForConfirmation
);
console.log('Stored at block:', result.block_height);
Parameters
| Parameter | Type | Description |
|---|
request | StoreRequest | Collection name and data array |
paymentCallback | function | Callback that receives a quote and returns payment result |
waitForConfirmation | boolean | Whether to wait for confirmation |
Bulk Creation
Store multiple documents at once:
const result = await client.store(
{
collection: 'users',
data: [
{ email: 'alice@example.com', name: 'Alice' },
{ email: 'bob@example.com', name: 'Bob' },
{ email: 'charlie@example.com', name: 'Charlie' }
]
},
async (quote) => {
const txHash = await processPayment(quote);
return { txHash, network: quote.network, sender: walletAddress, chainType: quote.chainType, paymentMethod: 'native' };
},
true
);
console.log('Stored at block:', result.block_height);
Error Handling
import { ValidationError, OnDBError } from '@ondb/sdk';
try {
await client.store(
{ collection: 'users', data: [{ email: 'alice@example.com' }] },
paymentCallback,
true
);
} catch (error) {
if (error instanceof ValidationError) {
console.log('Validation failed:', error.message);
} else if (error instanceof OnDBError) {
console.log('OnDB error:', error.code);
}
}
Next Steps
Read
Find and query documents
Update
Update existing documents