Back to Blog

OnchainDB Now Available in 4 Languages: TypeScript, Go, PHP, and Python

Store and monetize data from any backend. OnchainDB SDKs are now available for TypeScript, Go, PHP, and Python with consistent APIs across all languages.

OnchainDB Now Available in 4 Languages: TypeScript, Go, PHP, and Python

We’re excited to announce that OnchainDB is now available in four programming languages: TypeScript, Go, PHP, and Python. Whether you’re building a Node.js API, a Go microservice, a Laravel application, or a Python data pipeline, you can now store and monetize data with a consistent, familiar API.

Why Multi-Language Support?

Blockchain data storage shouldn’t be limited to a single ecosystem. Teams use different languages for different reasons - Go for performance-critical services, Python for data processing, PHP for web applications, TypeScript for full-stack JavaScript. OnchainDB now meets developers where they are.

All four SDKs share the same core concepts:

  • Fluent Query Builder - Chain methods to construct complex queries
  • Dual-Key Authentication - App keys for writes, user keys for Auto-Pay
  • x402 Payment Protocol - Native HTTP 402 support for monetization
  • Prisma-Style CRUD - Familiar patterns like findUnique, findMany, store

Quick Comparison

Here’s how you initialize a client and store data in each language:

TypeScript

import { createClient } from '@onchaindb/sdk';

const client = createClient({
  endpoint: 'https://api.onchaindb.io',
  appId: 'my-app',
  appKey: 'app_xxx...',
  userKey: 'user_yyy...'  // Optional: enables Auto-Pay
});

// Store data
await client.store({
  collection: 'users',
  data: [{ name: 'Alice', email: 'alice@example.com' }]
});

// Query with fluent builder
const users = await client.queryBuilder()
  .collection('users')
  .whereField('active').isTrue()
  .orderBy('createdAt', 'desc')
  .limit(10)
  .execute();

Go

import onchaindb "github.com/onchaindb/sdk-go"

client := onchaindb.NewClient(
    "https://api.onchaindb.io",
    "my-app",
    "app_xxx...",
    onchaindb.WithUserKey("user_yyy..."),  // Optional: enables Auto-Pay
)

// Store data
result, err := client.Store(
    "users",
    []map[string]interface{}{
        {"name": "Alice", "email": "alice@example.com"},
    },
    paymentProof,
)

// Query with fluent builder
users, err := client.QueryBuilder().
    Collection("users").
    WhereField("active").IsTrue().Done().
    OrderByDesc("createdAt").
    Limit(10).
    Execute()

PHP

use OnChainDB\OnChainDBClient;

$client = new OnChainDBClient(
    endpoint: 'https://api.onchaindb.io',
    appId: 'my-app',
    appKey: 'app_xxx...',
    userKey: 'user_yyy...'  // Optional: enables Auto-Pay
);

// Store data
$result = $client->store(
    collection: 'users',
    data: [['name' => 'Alice', 'email' => 'alice@example.com']],
    paymentProof: $paymentProof
);

// Query with fluent builder
$users = $client->queryBuilder()
    ->collection('users')
    ->whereField('active')->isTrue()
    ->orderBy('createdAt', 'desc')
    ->limit(10)
    ->execute();

Python

from onchaindb import OnChainDBClient

client = OnChainDBClient(
    endpoint="https://api.onchaindb.io",
    app_id="my-app",
    app_key="app_xxx...",
    user_key="user_yyy..."  # Optional: enables Auto-Pay
)

# Store data
result = client.store(
    collection="users",
    data=[{"name": "Alice", "email": "alice@example.com"}],
    payment_proof=payment_proof
)

# Query with fluent builder
users = (client.query_builder()
    .collection("users")
    .where_field("active").is_true()
    .order_by("created_at", "desc")
    .limit(10)
    .execute())

Feature Parity

All SDKs support the complete OnchainDB feature set:

FeatureTypeScriptGoPHPPython
CRUD OperationsYesYesYesYes
Query BuilderYesYesYesYes
JOINsYesYesYesYes
AggregationsYesYesYesYes
Blob StorageYesYesYesYes
Auto-PayYesYesYesYes
Task TrackingYesYesYesYes
Event SystemYesCallbacks--

Installation

Get started in seconds:

# TypeScript/Node.js
npm install @onchaindb/sdk

# Go
go get github.com/onchaindb/sdk-go

# PHP
composer require onchaindb/sdk

# Python
pip install onchaindb

Consistent Query Builder

The Query Builder works the same way across all languages. Complex queries with logical operators, date filters, and string matching are available everywhere:

Complex Conditions

TypeScript:

const users = await client.queryBuilder()
  .collection('users')
  .and(c => [
    c.whereField('status').equals('active'),
    c.or(o => [
      o.whereField('role').equals('admin'),
      o.whereField('role').equals('moderator')
    ])
  ])
  .execute();

Go:

users, _ := client.QueryBuilder().
    Collection("users").
    And(func(c *onchaindb.ConditionBuilder) []onchaindb.LogicalOperator {
        return []onchaindb.LogicalOperator{
            c.WhereField("status").Equals("active").Build(),
            c.Or(func(o *onchaindb.ConditionBuilder) []onchaindb.LogicalOperator {
                return []onchaindb.LogicalOperator{
                    o.WhereField("role").Equals("admin").Build(),
                    o.WhereField("role").Equals("moderator").Build(),
                }
            }),
        }
    }).
    Execute()

PHP:

$users = $client->queryBuilder()
    ->collection('users')
    ->find(fn($c) => $c->andGroup(fn() => [
        LogicalOperator::Condition($c->field('status')->equals('active')),
        $c->orGroup(fn() => [
            LogicalOperator::Condition($c->field('role')->equals('admin')),
            LogicalOperator::Condition($c->field('role')->equals('moderator')),
        ]),
    ]))
    ->execute();

Python:

users = (client.query_builder()
    .collection("users")
    .and_group(lambda c: [
        c.where_field("status").equals("active"),
        c.or_group(lambda o: [
            o.where_field("role").equals("admin"),
            o.where_field("role").equals("moderator"),
        ])
    ])
    .execute())

Auto-Pay Simplifies Payments

When you provide a userKey and the user has granted authorization to the broker, payments happen automatically. No payment callbacks needed:

// Without Auto-Pay - requires payment callback
await client.store(
  { collection: 'data', data: [{ content: 'example' }] },
  async (quote) => {
    const txHash = await wallet.pay(quote.brokerAddress, quote.totalCostTia);
    return { txHash, network: 'mocha-4' };
  }
);

// With Auto-Pay - just call store()
const clientWithAutoPay = createClient({
  endpoint: 'https://api.onchaindb.io',
  appId: 'my-app',
  appKey: 'app_xxx...',
  userKey: 'user_yyy...'
});

await clientWithAutoPay.store({
  collection: 'data',
  data: [{ content: 'example' }]
});

Documentation

We’ve updated our documentation to cover all four SDKs with code examples in every language:

Get Started

  1. Create an app on the OnchainDB Dashboard
  2. Install the SDK for your language
  3. Follow the quickstart to store your first data

Have questions? Join us on GitHub or reach out at support@onchaindb.io.


We’re committed to making data monetization accessible to every developer and data provider, regardless of their language preference. Try it out and let us know what you build!