Docs

TypeScript sample

Read canonical Torq resources with the checked-in TypeScript Developer Preview client.

Developer Preview. Use the SDK version and credential supplied with your approved application. Keep a secret key on your server; use an origin-bound publishable key in a browser.

This executable sample proves a typed canonical market read, query serialization, and bearer authentication without contacting a live environment.

Complete source

import assert from "node:assert/strict";

import { TorqClient } from "@torq-finance/sdk";

let requestedUrl = "";
let authorization = "";
const client = new TorqClient({
  baseUrl: "https://api.example.test",
  secretKey: "torq_test_sk_external_quickstart",
  fetch: async (input, init) => {
    requestedUrl = String(input);
    authorization = new Headers(init?.headers).get("authorization") ?? "";
    return new Response(
      JSON.stringify({
        items: [{ id: "market_1" }],
        pageInfo: { hasMore: false, nextCursor: null },
        freshness: { status: "current", lagSeconds: 0 }
      }),
      { status: 200, headers: { "content-type": "application/json" } }
    );
  }
});

const markets = await client.resources.markets.list<{ id: string }>({ limit: 1 });
assert.equal(markets.items[0]?.id, "market_1");
assert.equal(requestedUrl, "https://api.example.test/v1/markets?limit=1");
assert.equal(authorization, "Bearer torq_test_sk_external_quickstart");
console.log("TypeScript Torq SDK quickstart passed.");

Configure the approved Torq base URL and secret-manager-backed credential for your application. For a connected customer wallet, continue with the few-line Earn quickstart.

On this page