[英]How can I create a new account or address with web3.js?
I'm trying to interact with geth
, and I need to create a new deposit address (and be able to control it). 我正在尝试与geth
进行交互,并且我需要创建一个新的存款地址(并能够对其进行控制)。 How can I implement this with web3.js? 如何使用web3.js来实现呢?
You can use the Web3.eth.accounts.create() function. 您可以使用Web3.eth.accounts.create()函数。 It will return an account object which you'll be able to control. 它将返回一个您可以控制的帐户对象。 https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html https://web3js.readthedocs.io/zh/1.0/web3-eth-accounts.html
Example: 例:
var Web3 = require("web3");
var web3 = new Web3('http://localhost:8545'); // your geth
var account = web3.eth.accounts.create();
You can also use the web3.eth.personal.newAccount() function. 您也可以使用web3.eth.personal.newAccount()函数。 http://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#newaccount http://web3js.readthedocs.io/zh/1.0/web3-eth-personal.html#newaccount
Check this blog post to help determine which is right for you. 检查此博客文章,以帮助确定最适合您的博客。 https://medium.com/@andthentherewere0/should-i-use-web3-eth-accounts-or-web3-eth-personal-for-account-creation-15eded74d0eb https://medium.com/@andthentherewere0/should-i-use-web3-eth-accounts-or-web3-eth-personal-for-account-creation-15eded74d0eb
Edit: This answer is for Web3.js 1.0. 编辑:此答案适用于Web3.js 1.0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.