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

岁月 岁月 提出于 2021-06-16 14:58 7170 浏览

在研究自动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
        );
Tiny熊

擅长:智能合约,以太坊 · 采纳率 33% · 回答于 2021-06-16 17:07

其它 3 个回答

三火-0xstan 2021-06-16 15:15
岁月 2021-06-16 23:59
Sunny 2021-12-18 11:53

写回答

你需要登录后才可以回答问题,登录