[Ethereum] What exactly web3.eth.accounts.create do

accountsgo-ethereumweb3js

When web3.eth.accounts.create is used to create an account something like this can be seen.

web3.eth.accounts.create();
> {
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

now if web3.eth.accounts.encrypt(privateKey, password); is executed using the same privatekey that we got from the previous step we can get a output as the web3 keystore v3 standard. Now if we store this file in the geth node's keystore folder (ex user/.ethereum/private/keystore) and run personal.listAccounts we can get our created address on that list.

So when I need to unlock this account with web3.personal.unlockAccount what would be the passphrase that I need to give to unlock my account?

Best Answer

web3.eth.accounts.create(); already creates a new account

You can look the new account info using something like this in js:

var account = web3.eth.accounts.create(); //Creates the account (is an object) console.log(account); //show the object in the console

Then, if you want to get the keystore you have to provide the privateKey and a password using something like this:

var walletprivate = account["privateKey"]; //Get the private key from the object var phppasswallet = "THE_PASSWORD"; //provide a password var keystore = web3.eth.accounts.encrypt(walletprivate, phppasswallet); //Get the keystore

But this is just if you want the keystore for the account; with the web3.eth.accounts.create(); the account is already created and you can use it directly with the private key