npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@unifi-io/openocean-sdk

v0.0.1

Published

TypeScript SDK for OpenOcean Aggregator API - DEX aggregator supporting 40+ blockchain networks

Readme

OpenOcean Node SDK

npm version License: MIT

A TypeScript SDK for OpenOcean Aggregator API - the ultimate DEX aggregator supporting 40+ blockchain networks.

Features

  • 🌐 Multi-Chain Support: 40+ EVM and Non-EVM chains including Ethereum, BSC, Polygon, Arbitrum, and more
  • 💱 Best Rates: Find optimal swap routes across 100+ DEXs
  • 🔒 Type-Safe: Full TypeScript support with comprehensive type definitions
  • 🚀 Easy to Use: Simple and intuitive API
  • 📦 Lightweight: Minimal dependencies
  • Fast: Optimized for performance

Installation

npm install @unifi-io/openocean-sdk
# or
yarn add @unifi-io/openocean-sdk
# or
pnpm add @unifi-io/openocean-sdk

Quick Start

import { OpenOceanSDK, Chain } from '@unifi-io/openocean-sdk'

// Initialize the SDK
const sdk = new OpenOceanSDK()

// Get a quote for swapping tokens
const quote = await sdk.getQuote({
  chain: Chain.BSC,
  inTokenAddress: '0x55d398326f99059ff775485246999027b3197955', // USDT
  outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC
  amountDecimals: '1000000000000000000', // 1 token with 18 decimals
  gasPriceDecimals: '5000000000', // 5 Gwei
  slippage: '1', // 1% slippage
})

console.log('Output amount:', quote.data.outAmount)
console.log('Price impact:', quote.data.price_impact)

API Reference

SDK Initialization

import { OpenOceanSDK } from '@unifi-io/openocean-sdk'

// Use default API endpoint
const sdk = new OpenOceanSDK()

// Or specify a custom API endpoint
const sdk = new OpenOceanSDK('https://custom-api.example.com/v4')

Methods

getTokenList(chain)

Get the list of supported tokens for a specific chain.

const tokenList = await sdk.getTokenList(Chain.BSC)
// or use chain ID
const tokenList = await sdk.getTokenList(56)

Returns: GetTokenListResponse


getDexList(chain)

Get the list of available DEXs for a specific chain.

const dexList = await sdk.getDexList(Chain.BSC)

Returns: GetDexListResponse


getGasPrice(chain)

Get current gas prices for a specific chain.

const gasPrice = await sdk.getGasPrice(Chain.BSC)
console.log('Standard:', gasPrice.data.standard)
console.log('Fast:', gasPrice.data.fast)
console.log('Instant:', gasPrice.data.instant)

Returns: GetGasPriceResponse


getQuote(params)

Get a quote for token swap without transaction data.

const quote = await sdk.getQuote({
  chain: Chain.BSC,
  inTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
  outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
  amountDecimals: '1000000000000000000',
  gasPriceDecimals: '5000000000',
  slippage: '1',
  // Optional parameters
  disabledDexIds: '2,6', // Disable specific DEXs
  enabledDexIds: '1,3,5', // Or enable only specific DEXs
})

Parameters:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | chain | ChainName \| number | ✅ | Chain name or chain ID | | inTokenAddress | string | ✅ | Input token address | | outTokenAddress | string | ✅ | Output token address | | amountDecimals | string | ✅ | Token amount with decimals (e.g., 1000000 for 1 USDT with 6 decimals) | | gasPriceDecimals | string | ✅ | Gas price with decimals | | slippage | string | ❌ | Slippage tolerance (0.05 to 50), default: 1 | | disabledDexIds | string | ❌ | Comma-separated DEX IDs to disable | | enabledDexIds | string | ❌ | Comma-separated DEX IDs to enable (higher priority) |

Returns: GetQuoteResponse


getSwapQuote(params)

Get a quote with executable transaction data.

const swapQuote = await sdk.getSwapQuote({
  chain: Chain.BSC,
  inTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
  outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
  amountDecimals: '1000000000000000000',
  gasPriceDecimals: '5000000000',
  slippage: '1',
  account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb', // Your wallet address
  referrer: '0x...', // Optional referrer address
})

// Use the transaction data
const tx = await wallet.sendTransaction({
  to: swapQuote.data.to,
  data: swapQuote.data.data,
  value: swapQuote.data.value,
  gasPrice: swapQuote.data.gasPrice,
})

Parameters: Same as getQuote() plus:

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | account | string | ✅ | User wallet address | | referrer | string | ❌ | Referrer address | | referrerFee | string | ❌ | Referrer fee in basis points |

Returns: GetSwapQuoteResponse


Static Methods

OpenOceanSDK.getSupportedChains()

Get all supported chains.

const chains = OpenOceanSDK.getSupportedChains()

OpenOceanSDK.getEVMChains()

Get only EVM chains.

const evmChains = OpenOceanSDK.getEVMChains()

OpenOceanSDK.getSwapAPIChains()

Get chains that support Swap API.

const swapChains = OpenOceanSDK.getSwapAPIChains()

OpenOceanSDK.getGaslessAPIChains()

Get chains that support Gasless API.

const gaslessChains = OpenOceanSDK.getGaslessAPIChains()

OpenOceanSDK.getChainId(chainName)

Get chain ID by chain name.

const chainId = OpenOceanSDK.getChainId('bsc') // Returns: 56

OpenOceanSDK.getChainName(chainId)

Get chain name by chain ID.

const chainName = OpenOceanSDK.getChainName(56) // Returns: 'bsc'

OpenOceanSDK.getChainInfo(chainName)

Get chain information by name.

const info = OpenOceanSDK.getChainInfo('bsc')

OpenOceanSDK.getNativeTokenAddress(chain)

Get native token address for a chain.

const nativeToken = OpenOceanSDK.getNativeTokenAddress('bsc')

Chain Constants

Use the Chain constant object instead of hardcoding chain names:

import { Chain } from '@unifi-io/openocean-sdk'

// Available chains
Chain.ETH          // Ethereum
Chain.BSC          // BNB Chain
Chain.POLYGON      // Polygon
Chain.ARBITRUM     // Arbitrum
Chain.OPTIMISM     // Optimism
Chain.BASE         // Base
Chain.AVAX         // Avalanche
Chain.LINEA        // Linea
// ... and 30+ more chains

Supported Chains

EVM Chains with Swap API

  • Ethereum (eth, Chain ID: 1)
  • BNB Chain (bsc, Chain ID: 56)
  • Base (base, Chain ID: 8453)
  • Polygon (polygon, Chain ID: 137)
  • Arbitrum (arbitrum, Chain ID: 42161)
  • Linea (linea, Chain ID: 59144)
  • Optimism (optimism, Chain ID: 10)
  • Avalanche (avax, Chain ID: 43114)
  • zkSync Era (zksync, Chain ID: 324)
  • Scroll (scroll, Chain ID: 534352)
  • Blast (blast, Chain ID: 81457)
  • Mantle (mantle, Chain ID: 5000)
  • And 25+ more...

Chains with Gasless API

Gasless swaps are available on: Ethereum, BSC, Base, Polygon, Arbitrum, and Linea.

Complete Example

import { OpenOceanSDK, Chain } from '@unifi-io/openocean-sdk'

async function swapTokens() {
  const sdk = new OpenOceanSDK()
  
  // Step 1: Get gas price
  const gasPrice = await sdk.getGasPrice(Chain.BSC)
  console.log('Current gas price:', gasPrice.data.fast)
  
  // Step 2: Get quote
  const quote = await sdk.getQuote({
    chain: Chain.BSC,
    inTokenAddress: '0x55d398326f99059ff775485246999027b3197955', // USDT
    outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC
    amountDecimals: '5000000000000000000', // 5 USDT
    gasPriceDecimals: gasPrice.data.fast,
    slippage: '1',
  })
  
  console.log('Input:', quote.data.inAmount, quote.data.inToken.symbol)
  console.log('Output:', quote.data.outAmount, quote.data.outToken.symbol)
  console.log('Price Impact:', quote.data.price_impact)
  console.log('Estimated Gas:', quote.data.estimatedGas)
  
  // Step 3: Get executable swap transaction
  const swapQuote = await sdk.getSwapQuote({
    chain: Chain.BSC,
    inTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
    outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
    amountDecimals: '5000000000000000000',
    gasPriceDecimals: gasPrice.data.fast,
    slippage: '1',
    account: '0xYourWalletAddress',
  })
  
  // Step 4: Send transaction (using ethers.js or web3.js)
  // const tx = await wallet.sendTransaction({
  //   to: swapQuote.data.to,
  //   data: swapQuote.data.data,
  //   value: swapQuote.data.value,
  //   gasPrice: swapQuote.data.gasPrice,
  // })
  
  console.log('Transaction data ready:', swapQuote.data.to)
}

swapTokens()

Error Handling

try {
  const quote = await sdk.getQuote({
    chain: Chain.BSC,
    inTokenAddress: '0x...',
    outTokenAddress: '0x...',
    amountDecimals: '1000000000000000000',
    gasPriceDecimals: '5000000000',
  })
} catch (error) {
  if (error instanceof Error) {
    console.error('Failed to get quote:', error.message)
  }
}

Development

# Install dependencies
yarn install

# Build the SDK
yarn build

# Run tests
yarn test

# Watch mode for tests
yarn test:watch

# Test with UI
yarn test:ui

TypeScript Support

This SDK is written in TypeScript and includes complete type definitions. All API responses and parameters are fully typed.

import type { 
  GetQuoteResponse, 
  GetSwapQuoteResponse,
  ChainInfo 
} from '@unifi-io/openocean-sdk'

API Documentation

For more details about the OpenOcean API, visit the official documentation.

License

MIT © Unifi.io

Links

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.