打印合同时未出现但在 Etherscan 上出现的方法

问题描述 投票:0回答:1

我有一份 goerli 测试网合约 你可以在这里查看。我尝试使用 web3js 使用 javascript 函数调用

executeFlashLoan
,但代码的行为就好像该函数不存在一样。然而,它在 etherscan 页面上清晰可见。为什么我无法使用它?详细信息如下。下面是它在 javascript 中的调用方式:

const tradeData = await arbitrage.methods.executeFlashLoan(tradeInstructions).encodeABI();

合约已经在goerli上验证并发布了,如果你想看全文的话,相关部分在这里:

...

contract ArbitrageFlashLoan {

...

    function executeFlashLoan(TradeInstruction[] memory _tradeInstructions) external {
    
        // Step 1: Initiate flash loan
        require(_tradeInstructions.length > 0, "No trade instructions added");
    
        address[] memory assets = new address[](_tradeInstructions.length);
        uint256[] memory amounts = new uint256[](_tradeInstructions.length);
        uint256[] memory modes = new uint256[](_tradeInstructions.length);
    
        assets[0] = _tradeInstructions[0].inputToken;
        amounts[0] = _tradeInstructions[0].amountIn;
        modes[0] = 0; // 0 for no debt swap, 1 for debt swap
    
        lendingPool.flashLoan(
            address(this),
            assets,
            amounts,
            modes,
            address(this),  // Use the same address for onBehalfOf
            abi.encodeWithSignature("executeTrades(TradeInstruction[] memory)", _tradeInstructions),
            0
        );
    }
    
    ...

}

...

当通过 js 函数调用时,这总是会导致错误:

TypeError: arbitrage.methods.executeFlashLoan is not a functionat executeTrades (/Users/Me/triBot/dfsBot.js:1088:51)at Subscription.callback (/Users/Me/triBot/dfsBot.js:140:21)at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

当我部署合约时,我将其打印回来,方法部分如下所示(已缩短,但您会看到重要的内容):

methods: {
AAVE_LENDING_POOL_ADDRESS: [Function: bound _createTxObject],'0x878a0135': [Function: bound _createTxObject],'AAVE_LENDING_POOL_ADDRESS()': [Function: bound _createTxObject],
executeFlashLoan: [Function: bound _createTxObject],'0xe7bbc595': [Function: bound _createTxObject],'executeFlashLoan((address,address,bool,uint256,uint256)[])': [Function: bound _createTxObject],
executeTrades: [Function: bound _createTxObject],'0x07ed26d5': [Function: bound _createTxObject],'executeTrades((address,address,bool,uint256,uint256)[])': [Function: bound _createTxObject],
fee: [Function: bound _createTxObject],'0xddca3f43': [Function: bound _createTxObject],'fee()': [Function: bound _createTxObject],
lendingPool: [Function: bound _createTxObject],'0xa59a9973': [Function: bound _createTxObject],'lendingPool()': [Function: bound _createTxObject],

... etc.

但是,当我现在打印方法时,它看起来像这样:

{
WETH: [Function: bound _createTxObject],'0xad5c4648': [Function: bound _createTxObject],'WETH()': [Function: bound _createTxObject],
currencies: [Function: bound _createTxObject],'0x6036cba3': [Function: bound _createTxObject],'currencies(address)': [Function: bound _createTxObject],
owner: [Function: bound _createTxObject],'0x8da5cb5b': [Function: bound _createTxObject],'owner()': [Function: bound _createTxObject],
sRouter: [Function: bound _createTxObject],'0x017c64b0': [Function: bound _createTxObject],'sRouter()': [Function: bound _createTxObject],
tokenToMarketId: [Function: bound _createTxObject],'0xb8268788': [Function: bound _createTxObject],'tokenToMarketId(address)': [Function: bound _createTxObject],
uRouter: [Function: bound _createTxObject],'0x5cf39049': [Function: bound _createTxObject],'uRouter()': [Function: bound _createTxObject],
executeTrade: [Function: bound _createTxObject],'0x1395dd23': [Function: bound _createTxObject],'executeTrade(bool,address,address,uint256)': [Function: bound _createTxObject],
callFunction: [Function: bound _createTxObject],'0x8b418713': [Function: bound _createTxObject],'callFunction(address,(address,uint256),bytes)': [Function: bound _createTxObject]}

这显然和我发表的不一样。然而,当你查看 Etherscan 时,我所有的事件和方法都在那里。为什么会发生这种情况?是不是合同太新了,需要更多时间?

javascript json ethereum blockchain smartcontracts
1个回答
0
投票

我在调用合约时指出了错误的 ABI。通过纠正这个问题解决了。

© www.soinside.com 2019 - 2024. All rights reserved.