For the complete documentation index, see llms.txt. This page is also available as Markdown.

SDK

The Mimic Protocol SDK provides a TypeScript client to interact with the Mimic Protocol blockchain automation platform. It offers a developer-friendly interface for managing functions, triggers, executions, and intents.

Getting Started

You can install Mimic Protocol's SDK by running the following command line:

yarn add @mimicprotocol/sdk

Basic Client Initialization

import { Client } from '@mimicprotocol/sdk'

// Basic client with default configuration
const client = new Client()

// Client with custom base URL
const client = new Client({
  baseUrl: 'https://api-protocol.mimic.fi'
})

Client with Authentication

import { Client, ApiKeyAuth, BearerAuth } from '@mimicprotocol/sdk'

// Using API key authentication
const client = new Client({
  auth: new ApiKeyAuth('your-api-key')
})

// Using Bearer token authentication
const client = new Client({
  auth: new BearerAuth('your-bearer-token')
})

Client with Signer

Domain Clients

The SDK is organized into domain-specific clients, each handling a specific aspect of the protocol.

Balances

Query balance entries and compute totals.

Functions

Manage WASM functions and their manifests.

Triggers

Manage function triggers and their lifecycle. Triggers define how and when functions should be executed.

Trigger deactivation supports batching. A single signature can deactivate multiple triggers as long as they belong to the same signer.

Trigger Config Types

Cron Trigger Config

Event Trigger Config

For example, if you want to track:

you should set topics to:

Once Trigger Config

You can also use createExecuteOnceTriggerConfig() to create an execute once trigger config.

Executions

Query function execution history and results. The list and detail endpoints return execution metadata, fee breakdown, and validations. Inputs, outputs, and logs are fetched separately through dedicated methods.

Intents

Query, encode, and decode intents and their operations. An intent contains one or more operations (intent.operations); each operation has an opType that identifies what it does.

Error Handling

The SDK uses structured error handling with the ApiError class.

TypeScript Types

The SDK exports comprehensive TypeScript types for all data structures:

Configuration Options

Client Configuration

Per-Domain Configuration

Best Practices

  1. Error Handling: Always wrap SDK calls in try-catch blocks and handle ApiError instances appropriately.

  2. Type Safety: Leverage TypeScript types for better development experience and compile-time error checking.

  3. Configuration Management: Use environment variables for sensitive data like API keys and private keys.

  4. Signer Management: In production, use secure signer implementations and never expose private keys in client-side code.

Last updated