Reputation: 1
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
Upvotes: 0
Views: 761
Reputation: 126
You will have to do it from the Dapp. You will have to use the private key to sign the operation of your vote. See this link: https://ethereum.stackexchange.com/questions/25839/how-to-make-transactions-using-private-key-in-web3 Was very helpful to me when I had to use execute operations in name of other addresses having their private keys.
Upvotes: 0