daitchain

TypeScript SDK Phase 1

Three packages that share a common chain client: @dait/core for chain types and queries, @dait/browser for Keplr + MetaMask wallet adapters, @dait/compute for high-level compute helpers (deploy, channel, verify).

Install

npm install @dait/core @dait/browser @dait/compute
# or yarn / pnpm

Node 20+. ESM only. TypeScript types ship inline (no separate @types/ package).

Quick tour

import { DaitClient } from "@dait/core";
import { connect } from "@dait/browser";
import { ComputeSession } from "@dait/compute";

// 1. Wallet (Keplr for Cosmos side, MetaMask for EVM side)
const wallet = await connect({ chainId: "dait-1" });

// 2. RPC + gRPC-Web client
const dait = new DaitClient({
  rpcUrl:    "https://rpc.daitchain.io",
  evmRpcUrl: "https://rpc.daitchain.io",
  wallet,
});

// 3. Open a session against a model. Internally:
//    - posts a Job to compute_market
//    - waits for the auction to settle on a host
//    - opens a state_channel with the winner
const session = await ComputeSession.open(dait, {
  modelId:    "qwen2.5-32b-instruct",
  maxCalls:   10_000,
  escrow_uDAIT: 5_000_000n,
  deadlineMs: Date.now() + 24 * 3600 * 1000,
});

// 4. Inference; SDK verifies the X-DAIT-Receipt header on every call
const reply = await session.infer({
  prompt: "Summarize this PDF",
  attachments: [pdfBlob],
});
console.log(reply.text);
console.log(reply.receipt.tokens_out, "tokens at", reply.receipt.price_uDAIT, "uDAIT");

// 5. Close cooperatively. Final ChannelState is settled on-chain.
await session.close();

Package layout

PackageExports
@dait/corechain types, Msg encoders, query helpers, Receipt schema
@dait/browserKeplr + MetaMask wallet adapters, unified connect()
@dait/computeComputeSession.open, verifyReceipt, buildSDL

Wallet adapters

The unified connect() returns a wallet that can sign both Cosmos transactions (Amino + Direct) and EVM transactions (EIP-1559). Behind the scenes it resolves to:

Receipt verification

Every session.infer() internally calls verifyReceipt() per SPUR-IC ยง7. You can call it directly:

import { verifyReceipt } from "@dait/compute";

const next = verifyReceipt(headers, requestBytes, responseBytes, channelState);
// returns updated ChannelState, or throws a typed error

Sending custom Cosmos messages

import { MsgRegisterTier } from "@dait/core/staking_tiers";

const tx = await dait.tx.broadcast([
  MsgRegisterTier.fromPartial({
    signer: wallet.cosmosAddr,
    tierId: 3, // Node
  }),
]);
console.log("tx hash:", tx.hash);

Status

Phase 0 scaffold. Cryptography primitives are stubbed with TODO Phase 1 until the on-chain modules are wired. Public publish to npm aligns with Phase 1 alpha.

See also