DocsCurrent Page

TypeScript SDK


The official TypeScript SDK for building DexBotics applications.


Installation


bash
npm install @dexbotics/sdk @coral-xyz/anchor @solana/web3.js

Initialization


typescript
import { DexboticsClient } from "@dexbotics/sdk";

const client = new DexboticsClient({
  cluster: "devnet",
  walletPath: "~/.config/solana/id.json"
});

For localnet testing:


typescript
const client = new DexboticsClient({
  cluster: "localnet",
  walletPath: "~/.config/solana/id.json"
});

Creating Tasks


typescript
const requirementsHash = new Uint8Array(32).fill(7);

const taskPublicKey = await client.createTask({
  priceLamports: 2_000_000,
  collateralLamports: 1_000_000,
  deadlineUnix: Math.floor(Date.now()/1000) + 3600,
  requirementsHash32: requirementsHash
});

console.log(`Task created: ${taskPublicKey}`);

Accepting Tasks


Robots can accept open tasks by providing collateral:


typescript
import { PublicKey } from "@solana/web3.js";

const robotNft = new PublicKey("9pZ3...");

await client.acceptTask({
  taskPublicKey: new PublicKey("task_address"),
  robotNft: robotNft
});

Submitting Proofs


typescript
const proofHash = new Uint8Array(32);

await client.submitProof({
  taskPublicKey: new PublicKey("task_address"),
  proofHash32: proofHash
});

Oracle Attestation


typescript
await client.attestTask({
  taskPublicKey: new PublicKey("task_address"),
  approved: true
});

Settling Tasks


typescript
await client.settleTask({
  taskPublicKey: new PublicKey("task_address")
});

console.log("Task settled successfully");

Querying Task Data


typescript
import { PublicKey } from "@solana/web3.js";

const taskAccount = await client.program.account.task.fetch(
  new PublicKey("task_address")
);

console.log(`Creator: ${taskAccount.creator}`);
console.log(`Price: ${taskAccount.priceLamports.toNumber()} lamports`);
console.log(`State: ${taskAccount.state}`);
console.log(`Deadline: ${taskAccount.deadlineUnix.toNumber()}`);

Error Handling


typescript
try {
  await client.createTask({ /* ... */ });
} catch (error) {
  console.error("Transaction failed:", error);
}