Last active
November 19, 2017 19:13
-
-
Save tomericco/af789ae2e148a10b3e746638d7eada7a to your computer and use it in GitHub Desktop.
Managing account against an Ethereum client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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