Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 896 characters in body
Source Link
bbusdriver
  • 1.2k
  • 2
  • 18
  • 33

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

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?

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;
  }
Source Link
bbusdriver
  • 1.2k
  • 2
  • 18
  • 33

How many functions allowed per contract? + solidity

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?