Skip to content

OneShot SDK (v2)

Unified cross-chain quoting, execution, and wallet helpers for CrossChain Swaps. Works in browsers, Node.js, or serverless environments.

Features

  • 🔄 Unified Cross-Chain Swaps - Seamless asset swaps across multi-chain networks
  • 💰 Unified Balances - Fetch and cache real-time balances across all supported chains
  • 📊 Smart Quoting Engine - Get accurate quotes with dynamic routes and live pricing
  • 🔍 Token Discovery - Unified token search, metadata, and price lookup
  • 🔗 Wallet-Agnostic Execution - Viem, Ethers, Solana, or custom wallet adapters

Core Concepts

  • Headless Core SDKOneShotSDK exposes quote, execution, balance, and token search APIs that run in browsers, serverless, or Node without any framework assumptions.
  • Framework Bindings – React hooks (backed by SWR) and Vue composables wrap the same SDK instance, giving you cached quotes, balances, and execution state while preserving idiomatic patterns for each framework.
  • Wallet Adapters – viem, ethers, and Solana adapters normalize transaction submission, confirmations, and chain switching; you can extend the AdaptedWallet interface for custom wallets.
  • Token & Balance APIs – shared helpers (getTokenList, getTokensData, getBalances) keep asset search, metadata, and portfolio views in sync across your app and backend services.

Providers Architecture

The SDK keeps a single OneShotSDK instance in context so every hook or composable pulls from the same client:

  1. React – wrap your app with OneShotProvider and call hooks such as useQuote or useBalances; each hook reads the provider context.
  2. Vue – call provideOneShot inside setup code or install OneShotPlugin on the app instance; composables (useQuote, useBalances, etc.) inject the SDK through Vue’s dependency injection.

Key Hooks

OneShot ships first-party React hooks and Vue composables, each wrapping the shared SDK instance:

  • useQuote(initialParams) – central cache for swap quotes with abort-safe refetching and setParams.
  • useExecuteTransaction() – orchestrates executeTransaction, exposing execute, stage, message, result, and error.
  • useBalances(initialParams?) – fetches unified EVM/SVM balances with automatic retries on address changes.
  • useTokenList() – paginated token search with caching per query + loadTokens/resetTokens.
  • useTokensData(addresses) – pulls metadata and pricing for curated token sets.

The Vue equivalents (useQuote, useExecuteTransaction, useBalances, etc.) mirror the same API but use reactive refs/computed values instead of SWR.

State Management

  • React hooks rely on SWR to share caches across components, abort inflight requests when params change, and keep previous data during refetches where it makes sense (balances).
  • Vue composables watch reactive inputs with watchEffect/watch, cancel work via AbortController, and refresh data when computed parameters update.
  • Global quote and balance params live in globalThis to ensure multiple components stay synchronized in React; Vue keeps refs inside each composable instance while still deduplicating calls through abort logic.
  • Execution state (stage, message, error, result) is owned by the useExecuteTransaction hook/composable so that UI elements can react to stage transitions without manual wiring.