Skip to content

Instantly share code, notes, and snippets.

@tomericco
Last active November 19, 2017 19:13
Show Gist options
  • Save tomericco/af789ae2e148a10b3e746638d7eada7a to your computer and use it in GitHub Desktop.
Save tomericco/af789ae2e148a10b3e746638d7eada7a to your computer and use it in GitHub Desktop.
Managing account against an Ethereum client
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
/*
* Creating account
*/
const passphrase = 'my-super-secret-passphrase'; // Get the passphrase from HTML form or any other way
web3.personal.newAccount(passphrase, (error, address) => {
user.setAddress(address);
});
/*
* Unlocking account
*/
const passphrase = 'my-super-secret-passphrase'; // Get the passphrase from HTML form or any other way
const address = '0x3eca3...23abe2'; // Get user's address from DB or user input
const isUnlocked = web3.personal.unlockAccount(address, passphrase, 100); // Use Geth API for unlocking the account
if (isUnlocked) {
// Send transaction...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment