0

I deployed a contract to ropsten and tried to call a method from frontend, but was getting

TypeError: Cannot read property 'call' of undefined

So I checked my instance via this.Test.deployed().then((instance) => { console.log(instance) } to see if I have the function, but this particular function was not there!

It's a public view returns function that returns a boolean. I have several public view returns functions in the contract, but I have no idea why this one was omitted. I didn't even get an error while creating a contract to ropsten. Is there a limit or something?

** Edit **

From Frontend:

  checkPrizeReceived(id: number, price: number): Promise<any> { 
    this.Test.setProvider(this.web3.currentProvider); 
    return this.Test.deployed().then((instance) => {
      console.log(instance)
        return instance.checkPrizeReceived.call(id, price);
    })
    .then((value) => {  
      return value;
    })
    .catch((e) => {
        console.log(e);
    });
  }

Solidity:

  function checkPrizeReceived(uint256 id, uint price) public view returns (bool) {
    for (uint i = 0; i < better[msg.sender].length; i++) {   
      if (better[msg.sender][i].id == id && better[msg.sender][i].price == price) {
        if (better[msg.sender][i].receivedPrize) {
          return true;
        }
      }
    }

    return false;
  }
3
  • can you provide the front-end code that you're using to call the contract?
    – qbsp
    Commented Mar 19, 2018 at 8:19
  • posted. I have several public view returns functions that I call like above which has no problem calling it.
    – bbusdriver
    Commented Mar 19, 2018 at 16:58
  • It is solved now. Turns out that truffle compiler was having a problem. Thanks anyways.
    – bbusdriver
    Commented Mar 19, 2018 at 17:08

2 Answers 2

0

The problem can be with "web3". Check what version of web3 you using.

In version 1.0 the calling contract is with .call() method https://web3js.readthedocs.io/en/1.0/web3-eth.html#id74

In version 0.2.x.x, you can call methods directly from contract instance

myContractInstance.myMethod(param1 [, param2, ...] [, transactionObject] [, defaultBlock] [, callback]);

Documentation for 0.2 version is here https://github.com/ethereum/wiki/wiki/JavaScript-API

1
  • Thanks Ivan. Truffle compiler was creating a problem which is solved now.
    – bbusdriver
    Commented Mar 19, 2018 at 17:09
0

There's no such thing as a maximum number of functions, just the maximum amount of gas per block, which includes in any case the whole bytecode of the contract.

First, if the function is not in the ABI but it's in your solidity code, you'll have to recompile and regenerate the ABI (and possibly redeploy the contract). If there are no errors during the process the function should be in the ABI this time.

Second, I think you are accessing the function in the wrong way. It should be as follows:

instance.checkPrizeReceived(id, price).call({from: "0x.........."});

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.