The ShibaSwap V1 SDK (@shibaswap/sdk) is a TypeScript/JavaScript library that lets you build on top of ShibaSwap V1—a Uniswap V2 fork originally inherited via SushiSwap—using familiar abstractions like Token, Pair, Route, and Trade. It runs in any JS environment (browsers, Node) and powers both quick hackathon prototypes and production-grade integrations. Under the hood:
  • It swaps in ShibaSwap’s factory and router addresses
  • Computes CREATE2 pair addresses offline
  • Fetches on-chain reserves via ethers
  • Generates all parameters needed to craft router transactions

Quick Start & Installation

This pulls in @shibaswap/sdk-core and ethers as dependencies.

Imports & Initialization

Fetching On-Chain Data

You must supply on-chain data for tokens and pairs.

Case 1: Tokens

To fetch decimals dynamically:

Case 2: Pairs

Pricing

Mid Price (Direct & Indirect)

For multi-hop (e.g., via USDC):

Execution Price (with Slippage)

Trading

The SDK does not send transactions. It generates transaction parameters for you to send manually via ethers.
Router Address: 0x03f7724180aa6b939894b5ca4314783b0b36b329 Example: Swap 1 ETH → DAI

Pair Addresses (CREATE2 vs On-Chain)

On-chain:
Off-chain via CREATE2:

Technical Reference

Pair

Route

Trade

Other Exports

  • FACTORY_ADDRESS: ShibaSwap V1 Factory Address
  • INIT_CODE_HASH: For CREATE2 address generation
  • MINIMUM_LIQUIDITY: Protocol-reserved
  • Errors: InsufficientReservesError, InsufficientInputAmountError

Complete Example

Here’s a complete example showing how to use the SDK to perform a swap:

Best Practices

Always use the SDK’s built-in functions for calculations rather than implementing your own. This ensures accuracy and consistency with the protocol.
Set appropriate slippage tolerance based on your use case. Lower values provide better prices but may fail more often.
Always verify token addresses and chain IDs before creating Token instances to avoid errors.
Never hardcode amounts or addresses in production code. Always fetch them dynamically from the blockchain or configuration.

Error Handling

The SDK provides specific error types for common scenarios: