添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
慈祥的黄瓜  ·  数据库home - 知乎·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams Cross-linking with ethereum.stackexchange.com/questions/47940/… , which is probably a better place for this question. user94559 May 8, 2018 at 17:40

You can use the Web3.eth.accounts.create() function. It will return an account object which you'll be able to control. https://web3js.readthedocs.io/en/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. http://web3js.readthedocs.io/en/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

Note: This answer is for Web3.js 1.0.

I believe you the output of web3.eth.accounts.create() should contain a private key. web3js.readthedocs.io/en/v1.2.0/web3-eth-accounts.html#create – nibty Aug 22, 2019 at 21:07 the accounts created through web3.eth.accounts.create() can't be used to make the transaction as we can't use them as a sender. It gives Error: sender account not recognized – Zeeshan Ahmad Khalil Nov 2, 2019 at 5:29 try web3.eth.accounts.wallet.add(account.privateKey) to solve Error: sender account not recognized – Mark Parris Feb 5 at 3:50

This is how you can create a new address with web3.js:

const Web3 = require('web3');
const web3 = new Web3('https://bsc-dataseed.binance.org/');
const privateKey = 'private key';
const account = web3.eth.accounts.privateKeyToAccount(privateKey);
console.log(`Account: ${account.address}`);
for (let i = 0; i < 3; i++) {
  const newAccount = web3.eth.accounts.create();
  console.log(`Address ${i + 1}: ${newAccount.address}`);
                As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
– alea
                Apr 29 at 17:48
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.