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
–
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.
–
–
–
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}`);
–
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.