Database
Zero-config database with typed collections and CRUD operations
The Varity SDK provides the core building blocks for your application: a zero-config database, credential management, and infrastructure utilities. Install it once and start building immediately.
v2.0.0-beta.2Database
Zero-config database with typed collections and CRUD operations
Credentials
Credential resolution, validation, and dev/production management
Infrastructure
Platform configuration and utilities via subpath imports
The most common pattern is the zero-config database:
import { db } from '@varity-labs/sdk';
// Define a collection with TypeScript typesconst users = db.collection<{ name: string; email: string }>('users');
// Createawait users.add({ name: 'Alice', email: 'alice@example.com' });
// Readconst allUsers = await users.get({ limit: 10, orderBy: 'name' });
// Updateawait users.update('user-id', { name: 'Alice Smith' });
// Deleteawait users.delete('user-id');Everything available from import { ... } from '@varity-labs/sdk':
| Export | Type | Description |
|---|---|---|
db | Database instance | Pre-configured singleton — use this for most apps |
Database | class | Database class. Constructor accepts optional Partial<DatabaseConfig> |
Collection | class | Typed CRUD class with add(), get(), update(), delete() methods |
import { db, Database } from '@varity-labs/sdk';
// Option 1: Use the pre-configured singleton (recommended)const posts = db.collection<{ title: string; body: string }>('posts');await posts.add({ title: 'Hello World', body: 'First post' });
// Option 2: Create a custom instance with your own configconst customDb = new Database({ proxyUrl: 'https://your-proxy.example.com', appToken: 'your-app-token',});const items = customDb.collection('items');| Export | Type | Description |
|---|---|---|
VARITY_DEV_CREDENTIALS | const (object) | Shared dev credentials containing privy.appId, thirdweb.clientId, and rateLimits |
resolveCredentials | function | (appId?, clientId?) => CredentialConfig — resolves with fallback to dev credentials |
validateCredentials | function | (appId, clientId) => void — throws if credentials are invalid |
isUsingDevCredentials | function | (appId?, clientId?) => boolean — check if using shared dev credentials |
isProductionCredentials | function | (appId?, clientId?) => boolean — check if using production credentials |
getCredentialWarning | function | (environment) => string | null — get a warning message if credentials need attention |
logCredentialUsage | function | (appId?, clientId?) => void — log which credentials are being used |
getUpgradeInstructions | function | () => string — get instructions for upgrading to production credentials |
import { resolveCredentials, isUsingDevCredentials, getCredentialWarning, VARITY_DEV_CREDENTIALS,} from '@varity-labs/sdk';
// Resolve credentials with automatic fallback to dev credentialsconst creds = resolveCredentials( process.env.NEXT_PUBLIC_PRIVY_APP_ID, process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID,);console.log(creds.privy.appId);console.log(creds.thirdweb.clientId);
// Check if using dev credentials (useful for showing warnings)if (isUsingDevCredentials()) { console.warn('Using shared dev credentials -- set your own before deploying');}
// Get environment-specific warningsconst warning = getCredentialWarning('production');if (warning) { console.warn(warning);}| Export | Type | Description |
|---|---|---|
VERSION | const (string) | SDK version ('2.0.0-beta.2') |
SDK_VERSION | const (string) | Same as VERSION |
import { VERSION } from '@varity-labs/sdk';
console.log(`Running Varity SDK ${VERSION}`);The SDK exports these TypeScript types from the main entry point:
import type { CredentialConfig, // { privy: { appId }, thirdweb: { clientId } } DatabaseConfig, // { proxyUrl?: string, appToken?: string } QueryOptions, // { limit?, offset?, orderBy? } Document, // { id: string, created_at?, updated_at?, [key]: any } CollectionResponse, // { success: boolean, data?: T, error?: string }} from '@varity-labs/sdk';For apps that need direct access to chain configuration, blockchain services, thirdweb integration, or gas tracking, the SDK provides subpath imports. These are separate from the main entry point and are primarily used by the UI Kit and CLI internally.
@varity-labs/sdk/chains)Chain definitions for Varity L3, Arbitrum, and Base networks, plus USDC formatting utilities.
import { varityL3, varityL3Testnet, formatUSDC, parseUSDC, formatAddress, getVarityExplorerUrl, USDC_DECIMALS, VARITY_USDC_ADDRESS, SUPPORTED_CHAINS,} from '@varity-labs/sdk/chains';
// Format a raw USDC amount (6 decimals) for displayconst display = formatUSDC(BigInt(1500000)); // "1.50"
// Parse a human-readable amount to rawconst raw = parseUSDC('25.00'); // BigInt(25000000)
// Get an explorer URLconst url = getVarityExplorerUrl('0xabc...');@varity-labs/sdk/blockchain)Direct blockchain interaction services for licensing and revenue splits.
import { BlockchainService, NFTLicensingService, RevenueSplitService,} from '@varity-labs/sdk/blockchain';@varity-labs/sdk/thirdweb)Wrappers around thirdweb services including Engine, Nebula, Storage, Bridge, Gateway, and x402.
import { createThirdwebWrapper, createEngineClient, createNebulaClient, createStorageClient, varietyTestnet, getVarityChain, isVarityChain, VARITY_TESTNET_RPC,} from '@varity-labs/sdk/thirdweb';@varity-labs/sdk/tracking)Track gas usage, calculate costs in USDC, and manage billing cycles.
import { trackGasUsage, trackTransactionGasUsage, waitForTransactionReceipt, calculateGasInUSDC, createGasTracker,} from '@varity-labs/sdk/tracking';You may see references to a class-based SDK pattern (createVaritySDK, sdk.connect(), sdk.storage, sdk.analytics, etc.) in older code or documentation. This v1 API exists in the SDK source code but is currently commented out and not exported from the package.
The current SDK (v2.0.0-beta.2) uses a modular approach:
db singleton or create a Database instance directly/chains, /blockchain, /thirdweb, /tracking)The class-based API may be re-enabled in a future release once the underlying infrastructure is fully set up.
Installation
Get the SDK installed and configured in your project. View Guide
Infrastructure Config
Learn about chain configuration and utilities. View Guide