For the call of a smart contract funtion i want to call it from a different account then the one i have currently in meta mask. So i want to call this method by:

myContract.setFinished(true, {from: web3.eth.accounts[1], gas: 3000000}, function(err, res){});

But currently web3.eth.accounts[1] is undefined, so how can i set this account with a given private key or/ and address?

2 Answers 2

geth account new 

and then Geth will ask you to set a password for the account. Simple as that!

Or in the console:


In web3 the accounts are handled as array, i.e. if your keystore contains wallets like

1. UTC--2017-11-29T07-19-07.738904169Z--d4cefe4bc33681c9eac5c0ecbca2f36c12a20561  
2. UTC--2017-11-29T09-29-42.039767053Z--ee0997d7deb637a4441c54c4547b61d059b269b6

Your web3.eth.accounts[1] would be ee0997d7deb637a4441c54c4547b61d059b269b6.

web3.eth.accounts[1] is undefined because you dont have a second address. You can create a new account as mentioned in the above answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.