π±Swap
This guide demonstrates how to fetch token data, quote, and execute token swaps using the Holdstation ethers-v5 SDK.
Installation
npm install @holdstation/worldchain-sdk \\
@holdstation/worldchain-ethers-v5 \\
ethers@^5.8.0Setup
import { ethers } from "ethers";
import { Client, Multicall3, Quoter, SwapHelper } from "@holdstation/worldchain-ethers-v5";
import { config, TokenProvider } from "@holdstation/worldchain-sdk";
// 1. Create your JSONβRPC provider
const RPC_URL = "<https://worldchain-mainnet.g.alchemy.com/public>";
const provider = new ethers.providers.StaticJsonRpcProvider(RPC_URL, {
chainId: 480,
name: "worldchain",
});
// 2. Wire up the SDK client
const client = new Client(provider);
const multicall = new Multicall3(provider);
config.client = client;
config.multicall3 = multicall;
// 3. Helpers for tokens & swaps
const tokenProvider = new TokenProvider();
const quoter = new Quoter(client);
const swapHelper = new SwapHelper(client, { tokenStorage: config.tokenStorage });Contract Address
Include your target contract address in the configuration:
Overall Flow
Fetch token metadata (if you need decimals, symbol, etc.)
Preview routes (optional)
Get a live quote
Execute the swap
Detailed Examples
Token Metadata
Quote
Simple Quote
Smart Quote
SwapParams Interfaces
Quote Input
tokenIn
string
β
Address of input token
tokenOut
string
β
Address of output token
amountIn
string
β
Amount of input token (human units)
slippage
string
β
Max slippage in % (e.g. "0.3")
fee
string
β
Platform fee in % (e.g. "0.2")
Swap Input
tokenIn
string
β
Address of input token
tokenOut
string
β
Address of output token
amountIn
string
β
Amount of input token
tx
object
β
{ data, to, value } from quote()
fee
string
β
Fee in %
feeAmountOut
string
β
Absolute fee taken from output (optional)
feeReceiver
string
β
Address to receive fee (AddressZero if none)
Full Example & Further Reading
For a complete, endβtoβend swap example, and to explore all available methods, check out the SDK repo and docs:
π Documentation & Examples
Last updated