How to switch account without using metamask?

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

for example:

Hi @zoubair, and welcome to the Infura community! Just so I am clear and give you the correct feedback - are you looking to have multiple accounts, one for each user? Or are you looking to have one account with multiple private keys?

i’m looking for each address for one user

@Leiya_Kenney , do you have an idea how I can disconnect my address metatmask when the transaction finish I need to do this from web3.js

To get one address per user, you’d need to create a separate project for each user.

As far as disconnecting your MetaMask address when the transaction finishes, you can use disconnect (instructions here in the MetaMask docs), or you can take a look at this StackExchange thread for some more web3js-specific ideas.

I have deleted the duplicate thread on this, so all answers will be posted here in the future :slight_smile: