web3.eth.accounts.create - 创建账户
优质
小牛编辑
133浏览
2023-12-01
创建一个账户对象。
调用:
web3.eth.accounts.create([entropy]);
参数:
entropy
- String : 可选,用于增加混乱度的随机字符串,至少32字符长。如果未设定将使用randomhex生成一个随机字符串
返回值:
Object
- 账户对象,结构如下:
- address - string: 账户地址
- privateKey - string: 账户私钥,绝不要共享私钥或者在本地不加密保存!同时确保在使用后清空内存
- signTransaction(tx [, callback]) - Function: 用来对交易进行签名。
- sign(data) - Function: 用来对数据进行签名。
示例代码:
web3.eth.accounts.create();
> {
address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
web3.eth.accounts.create('2435@#@#@±±±±!!!!678543213456764321§34567543213456785432134567');
> {
address: "0xF2CD2AA0c7926743B1D4310b2BC984a0a453c3d4",
privateKey: "0xd7325de5c2c1cf0009fac77d3d04a9c004b038883446b065871bc3e831dcd098",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
web3.eth.accounts.create(web3.utils.randomHex(32));
> {
address: "0xe78150FaCD36E8EB00291e251424a0515AA1FF05",
privateKey: "0xcc505ee6067fba3f6fc2050643379e190e087aeffe5d958ab9f2f3ed3800fa4e",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}