Reputation: 31
How we generate address and private key using web3js in ethereum?
please someone help.
Upvotes: 3
Views: 7218
Reputation: 731
web3-eth-accounts
is the standalone package to perform account-related operations, see the following
Code Snippet
const Accounts = require('web3-eth-accounts')
const provider = 'wss://mainnet.infura.io/ws/v3/<your-infura-project-key>'
const accounts = new Accounts(provider)
const wallet = accounts.create()
console.log(`Private Key: \n${wallet.privateKey}`)
console.log(`Address: \n${wallet.address}`)
Output:
Private Key:
0xa81aa482c47342fb...
Address:
0x85fB46c47D8...
Upvotes: 0
Reputation: 60143
If you're using web3.js 1.0.0, see web3.eth.accounts.create
.
If you're using 0.2x.x, I don't think web3.js includes a way to do this, but you can use ethereumjs-wallet
.
Upvotes: 2