Examples

Examples (SDK vNext)

Looking to integrate with Treza using the new SDK? This page shows end‑to‑end examples: initializing the client, selecting a provider, creating enclaves, managing lifecycle, fetching logs, working with scheduled tasks, API keys, Docker Hub helpers, and GitHub OAuth—using real, copy‑pasteable snippets.

All snippets are TypeScript-first and work in Node 18+. See the /examples folder of treza-labs/treza-sdk for runnable files.


Installation

npm install @treza/sdk

Quick Start

import { TrezaClient } from '@treza/sdk';

const client = new TrezaClient({
  baseUrl: process.env.TREZA_BASE_URL ?? 'https://app.trezalabs.com',
  timeout: 30_000,
});

const WALLET = process.env.WALLET_ADDRESS!; // e.g. '0x4B0897b0513fdc7C541B6d9D7E929C4e5364D2dB'

async function main() {
  // 1) Discover providers
  const providers = await client.getProviders();
  const provider = providers[0];
  console.log('Using provider:', provider.name, provider.id);

  // 2) Create an enclave
  const enclave = await client.createEnclave({
    name: 'My Trading Bot',
    description: 'Secure environment for trading algorithms',
    region: provider.regions[0] ?? 'us-east-1',
    walletAddress: WALLET,
    providerId: provider.id,
    providerConfig: {
      dockerImage: 'trading-bot:latest',
      cpuCount: 2,
      memoryMiB: 512,
    },
  });

  console.log('Enclave created:', enclave.id, 'status:', enclave.status);

  // 3) Get logs (application-only)
  const appLogs = await client.getEnclaveLogs(enclave.id, 'application', 50);
  console.log('Application log entries:', (appLogs.logs.application ?? []).length);

  // 4) Pause → Resume lifecycle
  const paused = await client.pauseEnclave(enclave.id, WALLET);
  console.log('Paused →', paused.enclave.status);

  const resumed = await client.resumeEnclave(enclave.id, WALLET);
  console.log('Resumed →', resumed.enclave.status);
}

main().catch((e) => {
  console.error(e);
  process.exit(1);
});

Set these before running examples:

:::


Provider Management

Discover and inspect available providers (e.g., AWS Nitro), regions, and config schema.

Fetch a specific provider:


Enclave Management (Create / Update / Delete)


Enclave Lifecycle (Pause / Resume / Terminate)


Logs (Application, Errors, and Providers)

Available log types: all, ecs, stepfunctions, lambda, application, errors.


Docker Hub Helpers

Search images and list tags directly from the SDK.


Tasks (Scheduling inside Enclaves)

Update / delete tasks:


API Keys (Least-Privilege Access)

Update / delete keys:


GitHub OAuth (Optional)

Branches for a repo:

Connect a repo to an enclave:


Error Handling

TrezaSdkError includes message, code, statusCode, and optional details.


Types (What You Can Import)


Example Runner (Monorepo-friendly)

Structure your /examples folder like this:

Run any file with ts-node:


Troubleshooting

  • 401/403: Ensure your wallet address owns/has access to the resource.

  • 404: Wrong enclaveId or the resource belongs to a different wallet.

  • Lifecycle ops stuck: Check provider logs via getEnclaveLogs(enclaveId, 'all') and verify providerConfig (image exists, CPU/mem within quota).

  • Docker tag not found: Prefix official images with library/ (e.g., library/node).


See Also

  • API Reference(SDK Reference section)

  • Concepts → Providers, Enclaves, Lifecycle

  • Guides → Deploy your first enclave

Last updated