本文介绍了web3.eth.accounts.create 和 web3.eth.personal.newAccount 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,在使用 web3.eth.accounts.create() 时,它不会将帐户添加到链中(我使用 ganache-cli 进行测试),但 web3.eth.personal.newAccount() 会.

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 版本:1.0.0-beta.34

web3.js version: 1.0.0-beta.34

推荐答案

两个版本都在区块链上创建了一个新帐户.不同之处在于您如何与节点交互以及如何访问私钥.如果你有一个本地节点,你可以使用 web3.eth.accounts.create 这将创建帐户并为你提供对生成的私钥的访问,以便它可以存储在本地.但是,由于通过连接返回私钥并不安全,因此如果您通过 Infura 等提供商进行连接,则切勿使用这种方法来创建帐户.

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.

另一方面,您可以使用 web3.eth.personal 在远程节点上创建一个新帐户.在这种情况下,私钥将不会返回给您,因此您在访问您的帐户时会失去一些灵活性.当您没有私钥时,您无法在本地签署交易.为了运行事务,您必须在远程节点上调用 unlockAccount.请注意,您必须使用 web3.eth.personal 发送密码才能创建/解锁您的帐户,因此您仍然需要确保使用安全连接.

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.

这篇关于web3.eth.accounts.create 和 web3.eth.personal.newAccount 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:06
查看更多