Last active
May 6, 2018 17:28
-
-
Save GrandSchtroumpf/e138cd22112e61b101d4265046f0ca63 to your computer and use it in GitHub Desktop.
Ethereum simple wallet
This file contains 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 = 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