1

I am trying to call a delegate function from web3 but, everytime its saying its not

var myContract = new web3.eth.Contract(abi,add);
myContract.methods.enterMarkets(['cadd']).send({from:ethereum.selectedAddress});

error

Uncaught TypeError: myContract.methods.enterMarkets is not a function at <anonymous>:1:16

0xe7bc397DBd069fC7d0109C0636d06888bb50668c this is the smart contract on kovan

can you please explain how to call a delegateFunction from web3? with example would be great.

edit

smart contract 1 0xe7bc397DBd069fC7d0109C0636d06888bb50668c here

interface ComptrollerInterface {
/**
 * @notice Marker function used for light validation when updating the comptroller of a market
 * @dev Implementations should simply return true.
 * @return true
 */

/*** Assets You Are In ***/

function enterMarkets(address[] calldata cTokens) external returns (uint[] memory);
function exitMarket(address cToken) external returns (uint);

}

smart contract 2 0x1f5D7F3CaAC149fE41b8bd62A3673FE6eC0AB73b here

smart contract 3 0x3Afec0b1Ec510E59A757133059039828640839c7 enter link description here

contract Comptroller is ComptrollerV2Storage, ComptrollerInterface, ComptrollerErrorReporter, Exponential {
/**
 * @notice Add assets to be included in account liquidity calculation
 * @param cTokens The list of addresses of the cToken markets to be enabled
 * @return Success indicator for whether each corresponding market was entered
 */
function enterMarkets(address[] memory cTokens) public returns (uint[] memory) {
    uint len = cTokens.length;

    uint[] memory results = new uint[](len);
    for (uint i = 0; i < len; i++) {
        CToken cToken = CToken(cTokens[i]);

        results[i] = uint(addToMarketInternal(cToken, msg.sender));
    }

    return results;
}
}

sorry these are not my contracts, its from compound.finance on kovan Testnet but, most importantly how do we call delegateFunction from web3js?

this is the transaction working.

and i am trying to call the same on the same contract that is mentioned in the transaction but same error.

6
  • Can you please share the relevant part of your contract's code? Mar 5 '20 at 9:15
  • The error indicates that enterMarkets is not exposed in abi, which AFAIK, can be the result of only one thing - no external or public function named enterMarkets in your contract or in any contract up the inheritance line of your contract. Mar 5 '20 at 9:17
  • @goodvibration i have updated the code and the smart contracts detail
    – iamsujit
    Mar 5 '20 at 9:28
  • Like I said, your abi array probably does not include function enterMarkets. Please verify this (for example, with console.log(abi)). You might wanna make sure that you take the correct one, after compiling your contract. Mar 5 '20 at 9:34
  • @goodvibration yes thats true my abi does not have the enterMarkets function but then this transaction kovan.etherscan.io/tx/… is working in same sense
    – iamsujit
    Mar 5 '20 at 9:38
0

With myContract = new web3.eth.Contract(abi), the one and only reason for:

Uncaught TypeError: myContract.methods.enterMarkets is not a function

Is if abi is an array which does not include the following element:

{
    "constant"        : <true> or <false>,
    "inputs"          : [...],
    "name"            : "enterMarkets",
    "outputs"         : [...],
    "payable"         : <true> or <false>,
    "stateMutability" : <"pure"> or <"view"> or <"payable"> or <"nonpayable">,
    "type"            : "function"
}

There is absolutely no transaction or web3 call involved here, because your attempt to execute myContract.methods.enterMarkets fails before any RPC is even sent to the node. It's like trying to access x.y, where x is an object which doesn't have property y.

So you should inspect the local variable abi and figure out why it doesn't include that element. For example, perhaps it's the output of an old compilation, before you've added that function to the contract, or perhaps it's the output of the compilation of a totally different contract...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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