[英]How to create private key and public key with web3?
我想創建一個私鑰和公鑰,基本上是使用 web3 在以太坊中創建一個新帳戶。 但我想生成一個長度為 32 字節的私鑰。 有誰知道如何生成相同的? 使用了以下代碼,但無法生成 32 字節長的私鑰。
web3.eth.accounts.create();
以太坊使用 32 字節(即 64 個十六進制字符)長的私鑰。
您可以訪問使用privateKey
屬性中的accounts.create()
方法 ( docs ) 生成的privateKey
。
const account = web3.eth.accounts.create();
console.log(account.privateKey);
web3.eth.accounts.create() address: '0xB9b1415Dbd1B3C9a5890433DF8B2b389445CC6Fa', privateKey: '0x498262a4afde2bdd9e1bef3aafc6442ec36ccf167e527457a211118de93346ba', signTransaction: [Function: signTransaction], sign: [Function: sign], encrypt: [Function: encrypt]
私鑰在這里是'0x498262a4afde2bdd9e1bef3aafc6442ec36ccf167e527457a211118de93346ba',這是 64 位十六進制格式。
所以32 字節長度的私鑰是498262a4afde2bdd9e1bef3aafc6442ec36ccf167e527457a211118de93346ba
(刪除0x )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.