Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between web3.eth.accounts.create and web3.eth.personal.newAccount

Tags:

web3js

web3

As I understand when using web3.eth.accounts.create(), it doesn't add the account to chain (I'm using ganache-cli for testing), but web3.eth.personal.newAccount() does.

Is it the main purpose or is it a bug? Is there other differences?

web3.js version: 1.0.0-beta.34

like image 570
Galti Avatar asked Apr 29 '18 06:04

Galti


People also ask

What is Ethereum Web3 and web2?

Web2 refers to the version of the internet most of us know today. An internet dominated by companies that provide services in exchange for your personal data. Web3, in the context of Ethereum, refers to decentralized apps that run on the blockchain. These are apps that allow anyone to participate without monetising their personal data.

What is Web3 and why does it matter?

An internet dominated by companies that provide services in exchange for your personal data. Web3, in the context of Ethereum, refers to decentralized apps that run on the blockchain. These are apps that allow anyone to participate without monetising their personal data.

How to create a user account in Web3?

web3.js provides two packages to create user accounts, sign the transactions and perform other operations related to the user accounts. It says “web3.eth.accounts.create” on one hand and “web3.eth.personal.newAccount” on the other hand .

What is the difference between WEB2 and Web3 services?

These examples are illustrative of the main differences between web2 and web3 services. Web3 has some limitations right now: Scalability – transactions are slower on web3 because they're decentralized. Changes to state, like a payment, need to be processed by a miner and propagated throughout the network.


1 Answers

Both versions create a new account on the blockchain. The difference is how you interact with the node and having access to the private key. If you have a local node, you can use web3.eth.accounts.create which will create the account and provide you access to the private key generate so it can be stored locally. However, since returning the private key over a connection isn’t secure, you should never use this approach to create an account if you connect through a provider like Infura.

On the other hand, you can use web3.eth.personal to create a new account on a remote node. In this case, the private key will not be returned to you, so you lose some flexibility with accessing your account. When you don’t have the private key, you can’t sign transactions locally. In order to run transactions, you have to call unlockAccount on the remote node. Note that you have to send your password to create/unlock your account using web3.eth.personal, so you still need to make sure you using a secure connection.

Review this Medium blog post for additional info.

like image 140
Adam Kipnis Avatar answered Sep 23 '22 22:09

Adam Kipnis