【问题标题】:PancakeSwap Contract / Swaping token for another tokenPancakeSwap 合约 / 用另一个代币交换代币
【发布时间】:2021-07-17 07:03:51
【问题描述】:

我想通过 web3 使用 pancakeswap testnet contarct 将一些 testnet bep20 令牌交换到 busd(bep20)。 我查看了合同,但我无法理解“amountOutMin”和“路径”的含义。 我怎样才能用这个合同交换它们?请告诉我例子!

Pancakeswap 测试网合约

function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external virtual override ensure(deadline) returns (uint[] memory amounts) {
    amounts = PancakeLibrary.getAmountsOut(factory, amountIn, path);
    require(amounts[amounts.length - 1] >= amountOutMin, 'PancakeRouter: INSUFFICIENT_OUTPUT_AMOUNT');
    TransferHelper.safeTransferFrom(
        path[0], msg.sender, PancakeLibrary.pairFor(factory, path[0], path[1]), amounts[0]
    );
    _swap(amounts, path, to);
}

谢谢!

【问题讨论】:

    标签: swap smartcontracts web3 decentralized-applications binance-smart-chain


    【解决方案1】:

    amountOutMin 是您希望收到的最低金额。如果金额小于该金额,则交易将被撤销。这就像在 PancakeSwap 上设置滑点一样。

    Path 是交换所采用的路径。如果有直接路径,例如Token -> WBNB,路径就是["TOKEN_CONTRACT_ADDRESS", "WBNB_CONTRACT_ADDRESS"]

    【讨论】:

      猜你喜欢
      • 2022-08-13
      • 2018-12-28
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2019-01-15
      相关资源
      最近更新 更多