Skip to main content
Estimate operation costs before executing them using getPricingQuote(). All prices are returned in TIA.

Get Pricing Quote

// Estimate cost for a write operation
const quote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'write',
  size_kb: 50,
  collection: 'users',
  monthly_volume_kb: 1000 // Optional: for volume tier discounts
});

console.log('Total cost:', quote.total_cost, 'TIA');
console.log('Total cost:', quote.total_cost_utia, 'utia');
console.log('Celestia fee:', quote.base_celestia_cost, 'TIA');
console.log('Broker fee:', quote.broker_fee, 'TIA');
console.log('Indexing costs:', quote.indexing_costs);

PricingQuoteResponse Structure

interface PricingQuoteResponse {
  type: 'write_quote_with_indexing' | 'read_quote';

  // Base costs (TIA)
  base_celestia_cost: number;
  base_celestia_cost_utia: number;
  broker_fee: number;
  broker_fee_utia: number;

  // Indexing costs per field
  indexing_costs: Record<string, number>;      // field -> cost in TIA
  indexing_costs_utia: Record<string, number>; // field -> cost in utia

  // Total before price index fees
  base_total_cost: number;
  base_total_cost_utia: number;

  // Final total (includes price index fees if any)
  total_cost: number;
  total_cost_utia: number;

  // Metadata
  indexed_fields_count: number;
  request: PricingQuoteRequest;
  monthly_volume_kb: number;
  currency: string; // Always "TIA"

  // Optional: creator premium breakdown (if collection has premium)
  creator_premium?: { ... };

  // Optional: price index breakdown (if collection has Price index)
  price?: { ... };
}

Cost Breakdown

ComponentDescription
base_celestia_costBase cost for data availability
broker_feeOnchainDB broker fee
indexing_costsCost per indexed field
base_total_costSum of above costs
total_costFinal cost including any PriceIndex fees

Estimate Before Large Uploads

// Estimate cost for large file upload
const fileSizeKb = Math.ceil(fileBuffer.length / 1024);

const quote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'write',
  size_kb: fileSizeKb,
  collection: 'documents'
});

// Check if user wants to proceed
if (quote.total_cost > maxBudgetTia) {
  console.log(`Upload would cost ${quote.total_cost} TIA, exceeds budget`);
  return;
}

// Proceed with upload
await client.store({ collection: 'documents', data: fileData }, paymentCallback);

Batch Cost Estimation

// Estimate cost for batch operation
const records = generateRecords(1000);
const jsonSize = JSON.stringify(records).length;
const sizeKb = Math.ceil(jsonSize / 1024);

const quote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'write',
  size_kb: sizeKb,
  collection: 'batch_data',
  monthly_volume_kb: sizeKb // Current batch size
});

console.log(`Batch of ${records.length} records:`);
console.log(`  Size: ${sizeKb} KB`);
console.log(`  Cost: ${quote.total_cost} TIA`);
console.log(`  Per record: ${(quote.total_cost / records.length).toFixed(6)} TIA`);

Volume Tier Discounts

Include monthly_volume_kb to calculate volume-based discounts:
// Small volume
const smallQuote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'write',
  size_kb: 100,
  collection: 'data',
  monthly_volume_kb: 100
});

// Large volume - may get discount
const largeQuote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'write',
  size_kb: 100,
  collection: 'data',
  monthly_volume_kb: 100000 // 100 MB monthly volume
});

console.log('Small volume cost:', smallQuote.total_cost, 'TIA');
console.log('Large volume cost:', largeQuote.total_cost, 'TIA');

Read Operation Costs

// Estimate cost for read operation
const readQuote = await client.getPricingQuote({
  app_id: 'my_app',
  operation_type: 'read',
  collection: 'premium_data'
});

console.log('Read cost:', readQuote.total_cost, 'TIA');

Display Cost to Users

async function displayCostEstimate(data: any[], collection: string) {
  const jsonSize = JSON.stringify(data).length;
  const sizeKb = Math.ceil(jsonSize / 1024);

  const quote = await client.getPricingQuote({
    app_id: client.appId,
    operation_type: 'write',
    size_kb: sizeKb,
    collection
  });

  return {
    sizeKb,
    costTia: quote.total_cost,
    costUtia: quote.total_cost_utia,
    breakdown: {
      celestiaFee: quote.base_celestia_cost,
      brokerFee: quote.broker_fee,
      indexingFees: quote.indexing_costs
    }
  };
}

// Usage
const estimate = await displayCostEstimate(userData, 'users');
console.log(`This operation will cost ${estimate.costTia} TIA`);

Next Steps