I am calling smart contract function in Solidity from React, which should count the votes for the specific choices. The function works perfectly when I call it from my truffle console. However, when I call it from React application, the function is executed but votes are not counted.
function:
function doVote(uint _choice)
public
inState(State.Voting)
returns(bool voted)
{
bool found = false;
if(!voterRegister[msg.sender].voted ){
voterRegister[msg.sender].voted = true;
vote memory v;
v.voterAddress = msg.sender;
v.choice = _choice;
candidatesRegister[_choice].votes++ ;
votes[totalVote] = v;
totalVote++;
found = true;
}
return found;
}
in truffle console, this works:
> ballot = await Ballot.deployed()
> ballot.doVote(1)
In React I have this function where the address represents the public key of a user being logged in to the application:
export const doVote = async (choice, address)=> {
web3.eth.defaultAccount = address;
console.log("network: " + Contract.networks[networkID].address)
const BallotContract = new web3.eth.Contract(Contract.abi, Contract.networks[networkID].address);
return await BallotContract.methods
.doVote(choice)
};
if I add .call() to .doVote(choice) function will return "true"