0

I have a goerli testnet contract you can check out here. I'm trying to call executeFlashLoan using a javascript function using web3js, but the code acts as if the function doesn't exist. However, it's clearly visible on the etherscan page. Why am I not able to use it? Details below.

Here's how it's called in the javascript:

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

The contract is verified and published on goerli if you want to look over the whole thing, but the pertinent part is here:

...

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
        );
    }
   
   ...

}

...

This always results in the error as so when called via the js function:

TypeError: arbitrage.methods.executeFlashLoan is not a function
    at 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)

When I deployed the contract, I printed it back and the methods section looked like this (shortened but you'll see what's important):

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.

However, when I now print methods it looks like this:


{
  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]
}

This is obviously not the same as what I published. However, when you look at Etherscan, all my events and methods are there. Why is this happening? Is the contract just too new and it needs more time?

1
  • Are you configuring the arbitrage object correctly? Are you importing in that object the correct ABI from your smart contract? It seems just a problem with the ABI you import in the arbritage object. That object seems to refer to an arbitrage bot contract, like arb-bot or similar, not to your deployed contract. Dec 1, 2023 at 19:38

1 Answer 1

1

It seems just a problem with the ABI you import in the arbritage object. That object seems to refer to an arbitrage bot contract, like arb-bot or similar, not to your deployed contract.

1
  • Thank you! This was the answer. I was pointing to an old version of the ABI. Dec 2, 2023 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.