Add Account Management
This commit is contained in:
parent
1fbb827e78
commit
5286c07296
2 changed files with 42 additions and 0 deletions
13
Test.eth
Normal file
13
Test.eth
Normal file
|
@ -0,0 +1,13 @@
|
|||
pragma solidity ^0.4.18;
|
||||
|
||||
contract Test {
|
||||
int256 a = 0;
|
||||
|
||||
function set(int256 n) public {
|
||||
a += n;
|
||||
}
|
||||
|
||||
function get() public constant returns(int256) {
|
||||
return a;
|
||||
}
|
||||
}
|
29
geth_console.js
Normal file
29
geth_console.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
var Web3 = require('web3');
|
||||
var fs = require('fs');
|
||||
var web3 = new Web3();
|
||||
web3.setProvider(new web3.providers.HttpProvider('http://home.mrdev023.fr:8545'));
|
||||
|
||||
var account = undefined
|
||||
if(!fs.existsSync('account.json')){
|
||||
var password = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);;
|
||||
web3.eth.personal.newAccount(password).then(function(address){
|
||||
var obj = {"address": address, "password": password};
|
||||
console.log(address);
|
||||
fs.writeFile('account.json', JSON.stringify(obj), 'utf8',run);
|
||||
account = obj
|
||||
run();
|
||||
})
|
||||
} else {
|
||||
fs.readFile('account.json', 'utf8', function readFileCallback(err, data){
|
||||
if (err){
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
} else {
|
||||
account = JSON.parse(data); //now it an object
|
||||
run();
|
||||
}});
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
}
|
Loading…
Reference in a new issue