Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
npm install @holdstation/worldchain-sdk \\ @holdstation/worldchain-ethers-v5 \\ ethers@^5.8.0
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 });
const TARGET_CONTRACT = "0x43222f934ea5c593a060a6d46772fdbdc2e2cff0";
const info = await tokenProvider.details("0xTokenAddress");
const route = await quoter.simple(tokenIn, tokenOut); const smart = await quoter.smart(tokenIn, { slippage: 1, deadline: 300 });
const quoteParams = { tokenIn: tokenIn, tokenOut: tokenOut, amountIn: "1.5", slippage: "0.5", fee: "0.2", }; const quote = await swapHelper.quote(quoteParams);
const swapParams = { ...quoteParams, tx: { data: quote.data, to: quote.to, value: quote.value, }, feeAmountOut: quote.addons?.feeAmountOut, feeReceiver: ethers.constants.AddressZero, }; const receipt = await swapHelper.swap(swapParams); console.log("Transaction:", receipt.transactionHash);
// Single token const tokenInfo = await tokenProvider.details("0xTokenAddress"); console.log(tokenInfo); // Multiple tokens const infos = await tokenProvider.details( "0xToken1", "0xToken2", "0xToken3" ); console.log(infos);
const simpleQuote = await quoter.simple( "0xWETH", "0xUSDC" ); console.log(simpleQuote.best);
const smartQuote = await quoter.smart("0xWETH", { slippage: 2, // 2% deadline: 120, // seconds }); console.log(smartQuote.quote);
string
"0.3"
"0.2"
object
{ data, to, value }
quote()
AddressZero