簡體   English   中英

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

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

我們如何在以太坊中使用 web3js 生成地址和私鑰?

請有人幫忙。

如果您使用的是 web3.js 1.0.0,請參閱web3.eth.accounts.create

如果您使用的是 0.2xx,我認為 web3.js 不包含執行此操作的方法,但您可以使用ethereumjs-wallet

web3-eth-accounts是獨立的 package 進行賬戶相關的操作,見下文

代碼片段

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...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM