Skip to main content

Introduction

The Fibrous Router SDK is a TypeScript library that provides a simple and efficient way to integrate optimal token swaps into your decentralized applications. Built on top of the Fibrous Router API, it handles all the complexity of finding the best routes and executing swaps across multiple chains.

Why Use the SDK?

Type Safety

Full TypeScript support with comprehensive type definitions

Multi-Chain

Single interface for Base, HyperEVM, Scroll, and Starknet

Easy Integration

Simple API that abstracts away complex routing logic

Optimized Routes

Automatically finds the best swap paths across all DEXs

Supported Chains

The SDK supports the following blockchain networks:
ChainChain IDStatus
StarknetSN_MAINβœ… Full Support
Base8453βœ… Full Support
Scroll534352βœ… Full Support
HyperEVM998βœ… Full Support

Quick Start

1

Install the SDK

npm install fibrous-router-sdk
2

Initialize the Router

import { Router as FibrousRouter } from "fibrous-router-sdk";

const fibrous = new FibrousRouter();
3

Get the Best Route

const route = await fibrous.getBestRoute(
  inputAmount,
  tokenInAddress,
  tokenOutAddress,
  "base"
);
4

Execute the Swap

const tx = await fibrous.buildTransaction(
  inputAmount,
  tokenInAddress,
  tokenOutAddress,
  0.5, // 0.5% slippage
  userAddress,
  "base"
);

Key Features

πŸ” Smart Routing

The SDK automatically finds the optimal route by:
  • Aggregating liquidity from multiple DEX protocols
  • Splitting large trades across multiple paths
  • Minimizing price impact and slippage
  • Considering gas costs in route optimization

πŸ”„ Batch Operations

Execute multiple swaps in a single transaction (Starknet):
const routes = await fibrous.getBestRouteBatch(
  amounts,
  tokenInAddresses,
  tokenOutAddresses,
  "starknet"
);

🎯 Token Management

Easy access to supported tokens:
const tokens = await fibrous.supportedTokens(chainId);
const usdc = tokens.get("usdc");

⚑ Protocol Flexibility

Exclude specific protocols or use only certain ones:
const route = await fibrous.getBestRoute(
  amount,
  tokenIn,
  tokenOut,
  "base",
  {
    excludeProtocols: ["uniswap-v2"],
    direct: false
  }
);

Complete Example

Here’s a complete example of swapping tokens on Base:
import { Router as FibrousRouter } from "fibrous-router-sdk";
import { parseUnits } from "ethers";

async function swapTokens() {
  // Initialize router
  const fibrous = new FibrousRouter();
  const chainId = 8453; // Base
  
  // Get supported tokens
  const tokens = await fibrous.supportedTokens(chainId);
  const eth = tokens.get("eth");
  const usdc = tokens.get("usdc");
  
  if (!eth || !usdc) {
    throw new Error("Tokens not found");
  }
  
  // Prepare swap parameters
  const inputAmount = parseUnits("1", eth.decimals); // 1 ETH
  const slippage = 0.5; // 0.5%
  const userAddress = "0xYourAddress";
  
  // Get best route
  const route = await fibrous.getBestRoute(
    inputAmount,
    eth.address,
    usdc.address,
    "base"
  );
  
  console.log(`Input: ${route.inputAmount} ${eth.symbol}`);
  console.log(`Output: ${route.outputAmount} ${usdc.symbol}`);
  console.log(`Price Impact: ${route.priceImpact}%`);
  
  // Build transaction
  const tx = await fibrous.buildTransaction(
    inputAmount,
    eth.address,
    usdc.address,
    slippage,
    userAddress,
    "base"
  );
  
  // Execute with your wallet
  // const receipt = await wallet.sendTransaction(tx);
  
  return tx;
}

Chain-Specific Examples

  • Base
  • HyperEVM
  • Scroll
  • Starknet
const fibrous = new FibrousRouter();
const chainId = 8453;

const route = await fibrous.getBestRoute(
  parseUnits("1", 18),
  "0x0000000000000000000000000000000000000000", // ETH
  "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
  "base"
);

SDK vs API

  • When to Use SDK
  • When to Use API
βœ… Use the SDK when:
  • Building a TypeScript/JavaScript application
  • You want type safety and autocomplete
  • You need simplified integration
  • Working with multiple chains
  • You want built-in error handling

Requirements

  • Node.js: Version 18.x or higher
  • Web3 Provider: ethers.js v6+ or starknet.js v5+
  • TypeScript: Version 4.5+ (recommended)

Installation

npm install fibrous-router-sdk

Next Steps

Resources

Support

Need help? We’re here for you: