地址转换错误?数组传参数问题

在研究自动swap相关功能,遇到如下问题: 1、接口的函数定义:

interface IBakerySwapRouter {
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}

2、我的合约中的函数定义及调用

IBakerySwapRouter CBakeryRouter=IBakerySwapRouter(合约地址);
function _fSwap(uint _amountIn) payable public{
    CBakeryRouter.swapExactTokensForTokens(
        _amountIn,
        1,
        [0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee],
        0x5e9B3cdBa58249aBCCc0C7B9F53391194a8f128F,
        1823748811
    );
}

3、编译时出现如下错误:

TypeError: Invalid type for argument in function call. Invalid implicit conversion from address payable[1] memory to address[] memory requested.
[0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee],
请先 登录 后评论

最佳答案 2021-06-16 17:07

先构造一个address[] memory path , 参考代码:

address[] memory path  = new address[](1);
    path[0] = 0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee;

    router.swapTokensForExactTokens(
            _amountIn,
            1,
           path,
            0x5e9B3cdBa58249aBCCc0C7B9F53391194a8f128F,
            1823748811
        );
请先 登录 后评论

其它 3 个回答

三火-0xstan
请先 登录 后评论
岁月
请先 登录 后评论
Sunny
请先 登录 后评论
  • 4 关注
  • 0 收藏,4271 浏览
  • 岁月 提出于 2021-06-16 14:58

相似问题