Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Last active May 6, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/e138cd22112e61b101d4265046f0ca63 to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/e138cd22112e61b101d4265046f0ca63 to your computer and use it in GitHub Desktop.
Ethereum simple wallet
const web3 = new Web3('https://ropsten.infura.io/your-id');
// Create a account and store it encrypted in the localStorage
function createAndSaveAccount() {
const password = prompt('Mot de passe encrypter le compte');
const account = web3.eth.accounts.create();
const keystore = account.encrypt(password);
localStorage.setItem('keystore', JSON.stringify(keystore));
}
// Get the account in the localStorage and decrypt if with the password
function getAccount(password) {
const keystoreStr = localStorage.getItem('keystore');
const keystore = JSON.parse(keystoreStr);
return web3.eth.accounts.decrypt(keystore, password);
}
// Get the account and sign a message
function signMessage(message) {
const password = prompt('Sign a message');
return getAccount(password).sign(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment