I am new to Ethereum, I am developing a voting app following this example: https://github.com/dappuniversity/election
I want to create a new account and give private keys to users so they can cast their votes using their private keys. When I am switching accounts from Metamask, [msg.sender] account address also changes. I want to switch the account without Metamask so [msg.sender] can also change the account address. How can I achieve it? I don't want to switch the account address from Metamask.
function vote (uint _candidateId) public {
require(!voters[msg.sender]);
require(_candidateId > 0 && _candidateId <= candidatesCount);
// record that voter has already voted
voters[msg.sender] = true;
// update candidate voteCount
candidates[_candidateId].voteCount ++;
}
I am using Truffle v5.1.4, Solidity v0.5.12, Web3.js v1.2.1, and Ganache