[Ethereum] How to use not personal account web3

accountscontract-developmentprivate-keyweb3js

In my previous post I got answer but still I need some clarifications
let say when deploying contract with node js we have this line

 try {
    web3.personal.unlockAccount(web3.eth.coinbase, password);
} catch(e) {
    console.log(e);
    return;
}

which is unlocking account to make transaction for contract creation .

What if account is created with this way

web3.eth.accounts.create([entropy]);

And I have private key encyrpted somewhere on the system how I shall use it to unlock (or jsut use account) account let say after a week from it's creation ?

Also can u give details on what does entropy do
?

Is it like password in case of personal account ?

Thanks and sorry if questions are similar , there are not much resources to get more detailed info

Best Answer

Having a private key you can create a new account with web3.eth.accounts.wallet.add(account|privateKey)

You can use your account normally after.

// Create account
var account = web3.eth.accounts.create([entropy]);

// Load account
web3.eth.accounts.wallet.add(account)

// Set the account as the default
web3.eth.defaultAccount = account.address;

// Use it normally
web3.eth.signTransaction(transactionObject, address [, callback])

In the transactionObject you can omit the from parameter and the default account will be used.

Make sure to read the documentation

Related Topic