1

When I am calling voteForCandidate('Rama') function I am getting above mentioned error.

pragma solidity ^0.4.18;

contract Voting{

    mapping(bytes32 => uint8) public votesRecived;
    bytes32[] public candidateList;

    function Voting( bytes32[] candidateNames) public{
        candidateList = candidateNames;
    }

    function totalVotesFor(bytes32 candidate) public view returns(uint8){
        require(validCandidate(candidate));
        return votesRecived[candidate];
    }

    function voteForCandiadte(bytes32 candidate) public {
        require(validCandidate(candidate));
        votesRecived[candidate] += 1;

    }

    function validCandidate(bytes32 candidate) view public returns(bool){
        for(uint i = 0; i<candidateList.length; i++){
            if (candidateList[i] == candidate)
            {
                return true;
            }

        }
        return false;    
    }
    function candidateNamesFun() view public returns(bytes32[]){
        return candidateList;
    }

}

but other function are working properly but the call contractInstance.voteForCandidate("Rama") is returning error in node (web3js) cli using ganache-cli but its working fine in remix ide.

1

I think you missspelled Candidate in : voteForCandiadte

| improve this answer | |
1

There is no solidity function called voteForCandidate. Contract has voteForCandidate() function. Try to call contractInstance.voteForCandiadte("Rama") will work.

| improve this answer | |

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.