代币交换
交换类型
精确输入交换 (Exact Input)
// swapExactTokensForTokens
const amountIn = ethers.utils.parseEther("1.0"); // Exact input 1 TokenA
const amountOutMin = ethers.utils.parseEther("0.95"); // Minimum 0.95 TokenB
const path = [tokenA_address, tokenB_address];
const fees = [100]; // 1% fee rate
const to = userAddress;
const referrer = ethers.constants.AddressZero;
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // Expires in 20 minutes
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
path,
fees,
to,
referrer,
deadline
);精确输出交换 (Exact Output)
JU代币交换
用JU购买代币
用JU购买精确数量代币
卖出代币换JU
卖出代币换精确数量JU
交换前准备
1. 代币授权
2. 价格查询
3. 滑点设置
完整交换示例
基础代币交换
JU代币交换示例
高级功能
推荐人系统
批量交换
错误处理
常见错误及解决方案
最佳实践
1. 交换前检查
2. 价格影响计算
3. 动态滑点设置
监控和分析
交换事件监听
交换历史查询
Last updated