简体   繁体   English

Web3js 签名转换

[英]Web3js signTransation

I am following the documentation to be able to send test eth on the Kovan network from 1 account to another.我正在按照文档将 Kovan 网络上的测试 eth 从一个帐户发送到另一个帐户。 I was able to create the transaction and get back an output.我能够创建交易并获得输出。 But the balance is not updated and I can't find the transaction hash on Kovan ether scan https://web3js.readthedocs.io/en/v1.5.2/web3-eth-accounts.html#id6但是余额没有更新,我在 Kovan 以太扫描https://web3js.readthedocs.io/en/v1.5.2/web3-eth-accounts.html#id6上找不到交易哈希

web3.eth.accounts.signTransaction({
    to: account2,
    value: '50000000000000000',
    gas: 2000000
}, '0xPRIVATE-KEY')
.then(console.log);

{
  messageHash: '0xffcd0af7b86b21d2decef9a24a0270e5be77cb59e9ffb85357ad9a6ce2eb8af5',
  v: '0x77',
  r: '0xacf55d7733fe2432cc718cfe2ac5142005aaf67b9acb0a0822f2682dcf61a1d4',
  s: '0x21f50241acc1fef52a6131866b1e5a1e8ab0603e1a368db9f706fa1154978cda',
  rawTransaction: '0xf86b1a849502f900831e8480945c7cd53617506245cce6da0e0caf314903924cbf87b1a2bc2ec500008077a0acf55d7733fe2432cc718cfe2ac5142005aaf67b9acb0a0822f2682dcf61a1d4a021f50241acc1fef52a6131866b1e5a1e8ab0603e1a368db9f706fa1154978cda',
  transactionHash: '0xf29b0b9081f8b3ab4e142943e02e9135ff4a77d85db9707595d462377954e6bd'
}

signTransaction() only performs the signature. signTransaction()只执行签名。 It doesn't broadcast the (signed) transaction to the network.它不会将(已签名的)交易广播到网络。

For that, you can use sendSignedTransaction() ( docs ), which submits the (signed and serialized) tx data to the provider, and the provider broadcasts it to the network.为此,您可以使用sendSignedTransaction() ( docs ),它将(已签名和序列化的)tx 数据提交给提供者,然后提供者将其广播到网络。

web3.eth.sendSignedTransaction(signedTx.rawTransaction)
.on('receipt', console.log);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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