Quick Start

Quick Start

Get started with Tetrics SDK in less than 5 minutes! This guide will walk you through your first unified margin execution.

Installation

# Using npm
npm install @tetrics/sdk viem

# Using pnpm
pnpm add @tetrics/sdk viem

# Using yarn
yarn add @tetrics/sdk viem

Your First Execution

Let's stake ETH on Lido in just a few lines of code:

import { TetricsClient } from '@tetrics/sdk'

// 1. Create a client with your API credentials
const client = TetricsClient.fromApiKey(
  'your-api-key-id',
  'your-api-secret'
)

// 2. Define your execution plan
const plan = {
  name: 'Stake ETH on Lido',
  actions: [{
    chain: 'ethereum',
    protocol: 'lido',
    method: 'deposit',
    params: {
      amount: '1000000000000000000' // 1 ETH in wei
    },
    value: '1000000000000000000'
  }]
}

// 3. Execute the plan
const receipt = await client.executePlanDirect({
  name: plan.name,
  steps: plan.actions,
  executionMode: 'atomic'
})

console.log('Success!', receipt)

That's it! πŸŽ‰

You've just executed your first DeFi workflow with Tetrics. Here's what happened:

  1. Authentication: You created a client with your API credentials

  2. Plan Definition: You defined a simple staking action

  3. Execution: The SDK handled validation, signing, and on-chain execution

Getting an API Key

To use the SDK, you need an API key. Here's how to get one:

Option 1: API Key from Dashboard (Production)

  1. Connect your wallet

  2. Navigate to API Keys

  3. Click Create New Key

  4. Copy your key_id and secret (save it securely!)

Option 2: Wallet Authentication (Development)

For development, you can authenticate with your wallet:

Environment Variables

For production apps, use environment variables:

Common Patterns

Check API Health

Query Supported Protocols

Validate Execution Plan Before Running

Complete Example

Here's a full example with proper error handling:

Troubleshooting

"Authentication failed"

  • Check that your API key and secret are correct

  • Ensure you're using the right API URL

  • API keys expire - create a new one if needed

"Validation failed"

  • Check parameter formats (amounts should be strings in wei)

  • Verify protocol and method names are correct

  • Check that values match params for ETH transfers

"Rate limit exceeded"

  • The SDK automatically retries with exponential backoff

  • Consider upgrading your API plan for higher limits

  • Check the retry-after header for when to retry

Example: Gas Savings

Last updated