简体   繁体   English

在以太坊中使用 web3js 生成地址和私钥

[英]Generating address and private key using web3js in ethereum

How we generate address and private key using web3js in ethereum?我们如何在以太坊中使用 web3js 生成地址和私钥?

please someone help.请有人帮忙。

If you're using web3.js 1.0.0, see web3.eth.accounts.create .如果您使用的是 web3.js 1.0.0,请参阅web3.eth.accounts.create

If you're using 0.2xx, I don't think web3.js includes a way to do this, but you can use ethereumjs-wallet .如果您使用的是 0.2xx,我认为 web3.js 不包含执行此操作的方法,但您可以使用ethereumjs-wallet

web3-eth-accounts is the standalone package to perform account-related operations, see the following web3-eth-accounts是独立的 package 进行账户相关的操作,见下文

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: Output:

Private Key:
0xa81aa482c47342fb...

Address:
0x85fB46c47D8...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM