0

I am learning ethereum and I have setup a private node with geth. And have a simple client written to create account (web3 1.0 beta34) and list. While the account creation is successful, but it does not get listed,

code for account creation

var web3I    = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var accountI        = new Accounts(new Web3.providers.HttpProvider("http://localhost:8545"));

var createAccount   = async () => {

    var {address, privateKey, signTransaction, sign} = await accountI.create();    
    var password    = "password";
    var keyStore    =   accountI.encrypt(privateKey, password);

};

code for account listing

var getAccounts   = async () => {

    var accounts = await web3I.eth.getAccounts();    
    console.log("accounts address    ", accounts);    

};

getAccounts();

Q: Why does the account does not get listed?

0

I think accounts.create just creates a new account object. You probably want to use web3.eth.personal.newAccount instead. The following code works for me:

var web3I = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

var createAccount = async () => {
    var {address, privateKey, signTransaction, sign} = await web3I.eth.personal.newAccount('password');    
};
createAccount();

var getAccounts = async () => {
    var accounts = await web3I.eth.getAccounts();    
    console.log("accounts address    ", accounts);    
};
getAccounts();
  • 1
    Thanks. This did not completely solve the issue. I had to add this to my geth node '--rpcapi="db,eth,net,web3,personal,account' startup arguments and then it worked. – karts Apr 29 '18 at 7:24
0

Got it worked by using web3.eth.personal.newAccount and adding --rpcapi="db,eth,net,web3,personal,account" to my geth node startup agruments.

  • Be careful. Exposing personal over RPC could be vulnerable. – Prashant Prabhakar Singh Apr 29 '18 at 16:20
  • what is the correct way of doing this if i am to make my node public? – karts Apr 29 '18 at 17:06
  • Using IPC connection is best possible approach as of now. – Prashant Prabhakar Singh Apr 30 '18 at 4:19
  • how is IPC more secure than RPC? you still mention --port for ipc. Is it not possible to have a SSL with RPC with geth ? – karts May 1 '18 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.