Skip to main content

Installation

You can install Fibrous Router SDK using npm, yarn, or pnpm: Latest stable version: 1.0.1
npm install fibrous-router-sdk

Quick Start

Check out the detailed example in the Fibrous SDK Github Repository section for a simple example of how to initialize and use the SDK. Here’s a simple example of how to initialize and use the SDK:
import { Router as FibrousRouter, getBestRouteParams } from "fibrous-router-sdk";
import { parseUnits } from "ethers";

// Create a new router instance with v2 API
const fibrous = new FibrousRouter({
    apiVersion: "v2", // optional, v2 is the latest version
});

// Refresh and get supported chains
const chains = await fibrous.refreshSupportedChains();
const chainId = chains.find(chain => chain.chain_name == "hyperevm")?.chain_id;
if (!chainId) {
    throw new Error("Chain not supported");
}

// Build route options
const tokens = await fibrous.supportedTokens(chainId);
// Get input token from tokens map
const inputToken = tokens.get("usdc");
if (!inputToken) {
    throw new Error("Input token not found");
}
// Get output token by address (for unverified tokens)
const outputToken = await fibrous.getToken(
    "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb",
    chainId,
);
if (!outputToken) {
    throw new Error("Output token not found");
}
const tokenInAddress = inputToken.address;
const tokenOutAddress = outputToken.address;
const tokenInDecimals = Number(inputToken.decimals);
const inputAmount = BigInt(parseUnits("4", tokenInDecimals)); // 4 USDC

const getBestRouteParams: getBestRouteParams = {
    amount: inputAmount,
    tokenInAddress: tokenInAddress,
    tokenOutAddress: tokenOutAddress,
    chainId: chainId,
    options: {
        reverse: false,
    },
};

const route = await fibrous.getBestRoute(getBestRouteParams);

Requirements

  • Node.js version 18.x or higher
  • A Web3 provider (like ethers.js) for transaction signing
  • Access to supported blockchain networks (Base, Scroll, HyperEVM, Monad, or Starknet)

Next Steps

After installation, check out these guides to learn more about specific features: