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?

2 Answers 2

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
  • 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
    Commented Apr 29, 2018 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.

4
  • Be careful. Exposing personal over RPC could be vulnerable. Commented Apr 29, 2018 at 16:20
  • what is the correct way of doing this if i am to make my node public?
    – karts
    Commented Apr 29, 2018 at 17:06
  • Using IPC connection is best possible approach as of now. Commented Apr 30, 2018 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
    Commented May 1, 2018 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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