Tayyab Hussain
Tayyab Hussain

Reputation: 31

Generating address and private key using web3js in ethereum

How we generate address and private key using web3js in ethereum?

please someone help.

Upvotes: 3

Views: 7218

Answers (2)

basit raza
basit raza

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

user94559
user94559

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

Related Questions