繁体   English   中英

如何使用 web3 创建私钥和公钥?

[英]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.

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