如何使用web3.js创建新帐户或地址?

时间:2018-05-08 17:35:06

标签: ethereum web3js

我尝试与geth互动,我需要创建一个新的存款地址(并能够控制它)。我如何用web3.js实现这个?

1 个答案:

答案 0 :(得分:1)

您可以使用Web3.eth.accounts.create()函数。它将返回一个您可以控制的帐户对象。 https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html

示例:

var Web3 = require("web3");

var web3 = new Web3('http://localhost:8545'); // your geth
var account = web3.eth.accounts.create();

您还可以使用web3.eth.personal.newAccount()函数。 http://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#newaccount

查看此博客文章,以帮助确定哪种方式适合您。 https://medium.com/@andthentherewere0/should-i-use-web3-eth-accounts-or-web3-eth-personal-for-account-creation-15eded74d0eb

编辑:这个答案适用于Web3.js 1.0。