Go-Ethereum

乙太坊離線簽名者c#

  • September 19, 2018

是否有任何用於交易的離線簽名者的 C# 版本。像 ethereumjs-tx

var Tx = require(’ethereumjs-tx’) var privateKey = new Buffer(’e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109’, ‘hex’)

VAR rawTx = {隨機數:‘0×00’,gasPrice:‘0x09184e72a000’,gasLimit:‘0x2710’,到:“0x0000000000000000000000000000000000000000’,值:‘0×00’,數據:‘0x7f7465737432000000000000000000000000000000000000000000000000000000600057’}

var tx = new Tx(rawTx) tx.sign(privateKey)

var serializedTx = tx.serialize() console.log(serializedTx.toString(‘hex’))

在 c# 中需要類似我正在嘗試 nethereum 這個實現不起作用

如何使用 C# 簽署交易?

var privateKey = “0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7”; var senderAddress = “0x12890d2cce102216644c59daE5baed380d84830c”;

現在首先使用 web3,您需要檢索發件人地址的交易總數。

var web3 = new Web3(); var txCount = 等待 web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(senderAddress);

txCount 將用作對交易進行簽名的 nonce。

現在再次使用 web3,您可以建構一個編碼事務,如下所示:

var 編碼 = web3.OfflineTransactionSigning.SignTransaction(privateKey, receiveAddress, 10, txCount.Value);

如果您需要包含數據和氣體,則會出現過載。

您可以驗證編碼交易: Assert.True(web3.OfflineTransactionSigning.VerifyTransaction(encoded));

或者從編碼交易中獲取發件人地址:

web3.OfflineTransactionSigning.GetSenderAddress(編碼);

要發送編碼交易,您將“SendRawTransaction”

var txId = 等待 web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(“0x” + 編碼);

你基本上回答了你自己的問題。

https://nethereum.readthedocs.io/en/latest/introduction/web3/

您具有離線交易簽名功能,但文件尚未更新。方法呼叫現在看起來不同了,因為它被移動到靜態上下文或類似的東西:

Web3.OfflineTransactionSigner.SignTransaction …..

有關更多資訊,請查看:https ://github.com/Nethereum/Nethereum/issues/151

如果您想要基於 secp256k1lib 而不是 Bouncy Castle 的簽名者,那麼您可能希望使用 Nethermind 項目中的簽名者:

secp256k1lib 的代理: https ://github.com/tkstanczak/nethermind/tree/master/src/Nethermind/Nethermind.Secp256k1

您可能希望查看的乙太坊協議細節的實際使用以作為您的解決方案的基礎: https ://github.com/tkstanczak/nethermind/blob/master/src/Nethermind/Nethermind.Core/Crypto/EthereumSigner.cs

引用自:https://ethereum.stackexchange.com/questions/25386