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?