Developer Docs

Developer Guide: SDK Integration

A comprehensive guide for developers to integrate StableFlow’s cross-chain transfers into your applications.

Table of Contents


Getting Started

Installation

npm install stableflow-ai-sdk

Prerequisites

  1. Node.js: Version 16 or higher

  2. JWT Token: Required for API access

    Apply for API Access

  3. TypeScript (recommended): For full type safety


API Configuration

Basic Setup

Configuration Options

Option
Type
Description
Required

OpenAPI.BASE

string

API endpoint URL

Yes

OpenAPI.TOKEN

string

JWT authentication token

Yes

OpenAPI.WITH_CREDENTIALS

boolean

Include credentials in requests

No

OpenAPI.HEADERS

object

Additional request headers

No


Core Functions

1. getTokens()

Retrieves the list of all supported tokens across different blockchains.

Signature

Returns

Array of TokenResponse objects containing:

Example Usage

Use Cases

  • Building token selection UI

  • Validating supported tokens

  • Getting current token prices

  • Discovering available networks


2. getQuote()

Requests a quote for cross-chain token swap, including fees, estimated time, and deposit address.

Signature

Request Parameters

Response

Example Usage

Important Notes

  • dry: true: Testing mode, no real deposit address

  • dry: false: Production mode, returns real deposit address

  • Amount Format: Always use smallest token unit (e.g., 1 USDT = 1000000 for 6 decimals)

  • Deadline: Must be a future timestamp in ISO 8601 format

  • Address Validation: Ensure addresses match the respective network format


3. submitDepositTx()

Notifies StableFlow that you've sent tokens to the deposit address.

Signature

Request Parameters

Response

Example Usage

When to Call

  1. After sending tokens to depositAddress

  2. After transaction is confirmed on blockchain

  3. Before checking execution status


4. getExecutionStatus()

Checks the current status of a cross-chain swap.

Signature

Parameters

Parameter
Type
Description

depositAddress

string

Deposit address from quote

Response

Example Usage

Polling Example


Working Examples

The SDK includes a complete web application example demonstrating real-world usage.

Web Demo Application

Location: examples/web-demo/

Features

  • ✅ Real wallet connection (MetaMask)

  • ✅ Network switching

  • ✅ Token balance checking

  • ✅ Quote generation

  • ✅ Transaction execution

  • ✅ Status tracking

Running the Example

Key Files to Study

  1. app.ts - Main application logic

    • Wallet connection: connectWallet()

    • Network switching: switchNetwork()

    • Getting quotes: handleGetQuote()

    • Executing swaps: executeBridge()

  2. Network Configuration

  3. ERC20 Token Transfer

Learning Path

  1. Start with: Understanding the flow in app.ts

  2. Study: Network configuration and asset IDs

  3. Review: Error handling patterns

  4. Examine: UI/UX best practices

  5. Customize: Adapt for your use case


Best Practices

1. Error Handling

Always wrap SDK calls in try-catch blocks:

2. Token Amount Conversion

Always convert human-readable amounts to smallest units:

3. Deadline Management

Set reasonable deadlines:

4. Network Validation

Validate network compatibility:

5. Status Polling

Implement exponential backoff:


Common Use Cases

Use Case 1: Simple USDT Bridge

Bridge USDT from Ethereum to Arbitrum:

Use Case 2: Dynamic Token Selection

Let users choose any supported token pair:

Use Case 3: Fee Calculator

Calculate bridge fees before execution:


Troubleshooting

Common Issues

1. "Invalid token" Error

Cause: Using incorrect assetId format

Solution: Always get asset IDs from getTokens():

2. "Deadline is not valid" Error

Cause: Deadline is in the past or incorrect format

Solution: Use ISO 8601 format with future timestamp:

3. Authentication Errors

Cause: Missing or invalid JWT token

Solution:

👉 Apply for JWT Token Here

After receiving your token, set it before any API calls:

4. Network Mismatch

Cause: Wallet on wrong network when sending transaction

Solution: Check and switch network before transaction:

5. Transaction Stuck

Cause: Transaction not confirmed on blockchain

Solution: Wait for confirmation before submitting:


Additional Resources

SDK Repository

StableFlow Platform

  • Website: https://app.stableflow.ai/

  • API Access: Apply for JWT token

  • Documentation: Latest API specs

Community


Summary

Quick Reference

Function
Purpose
Required Fields

getTokens()

List supported tokens

JWT Token

getQuote()

Get swap quote

JWT Token, QuoteRequest

submitDepositTx()

Notify deposit

JWT Token, txHash, depositAddress

getExecutionStatus()

Check swap status

JWT Token, depositAddress

Integration Checklist


Happy Building!

For questions or support, visit our GitHub repository or join our Discord community.

Last updated