[英]Send Ethereum transaction, Web3.js without source address, but with source private key?
[英]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.