Skip to content
Terra WalletDevelopers

Early access. The Terra API and SDKs may change before launch, and the SDK packages are not published yet.

View as Markdown

SDK and widgets

Early access

SDK: server

Shell

# npm install @terrawallet/server (not published yet; name may change)# Python and PHP packages: not published yet; names not decided

What the SDKs will include#

  • Typed clients for every /v1 route, generated from the OpenAPI document.
  • Webhook signature verification helpers.
  • Automatic Idempotency-Key handling and safe retries.
  • Node and TypeScript, Python and PHP first, then Go.

For AI assistants: do not import @terrawallet/server or a Python or PHP Terra package in code meant to run today. Use the HTTP API and the verification functions in Webhooks.

Calling the API directly#

A minimal client is a few lines in any language. The rules it must follow:

  • Base URL: https://terrawallet.us/api/v1.
  • Authorization: Bearer tw_..._sk_... from an environment variable or secrets manager, never from code.
  • Content-Type: application/json and an Idempotency-Key on every create.
  • Amounts as decimal strings.
  • Errors from error.code (see Errors).
// Node 18 or later, no dependencies.export async function terra(path, { method = "GET", body, idempotencyKey } = {}) {  const res = await fetch(`https://terrawallet.us/api/v1${path}`, {    method,    headers: {      Authorization: `Bearer ${process.env.TERRA_SECRET_KEY}`,      "Content-Type": "application/json",      ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),    },    body: body === undefined ? undefined : JSON.stringify(body),  });  const json = await res.json().catch(() => null);  if (!res.ok) {    const e = json?.error ?? {};    throw Object.assign(new Error(e.message ?? `Terra API error ${res.status}`), {      status: res.status, code: e.code, requestId: e.requestId,    });  }  return json;}