Skip to main content
You need an API Key to use the Chainrails SDK. You can get one by signing up on our dashboard or contacting us at [email protected].

Overview

The Chainrails SDK (@chainrails/sdk) is a TypeScript SDK that provides a simple, type-safe interface for interacting with the Chainrails API. It handles authentication, request formatting, and error handling automatically, allowing you to focus on building your application.

Installation

npm install @chainrails/sdk

SDK Modules

The SDK is organized into the following modules:

Intents

Create and manage cross-chain transfer intents, track payment status, and retrieve intent information.

Router

Find optimal routes and analyze bridge availability for cross-chain transfers.

Quotes

Get real-time quotes for cross-chain transfers from various bridge providers.

Chains

Retrieve information about supported blockchain networks and tokens.

Client

Retrieve authenticated client information.

Language Support

Currently, the SDK is available for TypeScript/JavaScript

Authentication

The SDK uses API key-based authentication. Configure your API key once at startup:
import { Chainrails } from "@chainrails/sdk"

Chainrails.config({
  api_key: process.env.CHAINRAILS_API_KEY
})
The API key is automatically included in all requests via the Authorization: Bearer header.

Error Handling

The SDK throws errors for failed requests. Wrap SDK calls in try-catch blocks:
try {
  const intent = await crapi.intents.create({...})
} catch (error) {
  if (error instanceof Error) {
    console.error("Failed to create intent:", error.message)
  }
}

Retry Policy

The SDK automatically retries failed requests up to 2 times.

Type Definitions

The SDK includes full TypeScript type definitions for all requests and responses, providing autocomplete and type safety in your IDE.