1

is there any C# version of the offline signer for transaction. like ethereumjs-tx

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

var rawTx = { nonce: '0x00', gasPrice: '0x09184e72a000', gasLimit: '0x2710', to: '0x0000000000000000000000000000000000000000', value: '0x00', data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' }

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

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

need similar in c# i am trying nethereum this implementation not working

How can I sign a transaction using c#?

var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"; var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";

Now using web3 first you will need to retrieve the total number of transactions of your sender address.

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

The txCount will be used as the nonce to sign the transaction.

Now using web3 again, you can build an encoded transaction as following:

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

If you need to include the data and gas there are overloads for it.

You can verify an encoded transaction: Assert.True(web3.OfflineTransactionSigning.VerifyTransaction(encoded));

Or get the sender address from an encoded transaction:

web3.OfflineTransactionSigning.GetSenderAddress(encoded);

To send the encoded transaction you will "SendRawTransaction"

var txId = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);

1

You basically answered your own question.

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

You have offline transaction signing function but the docs have not been updated. The method call looks different now because it was moved to static context or something like that:

Web3.OfflineTransactionSigner.SignTransaction.....

For more info check this out: https://github.com/Nethereum/Nethereum/issues/151

0

If you would like a signer based on secp256k1lib instead of Bouncy Castle then you probably would like to use the signer from Nethermind project:

Proxy for secp256k1lib: https://github.com/tkstanczak/nethermind/tree/master/src/Nethermind/Nethermind.Secp256k1

Actual usage with Ethereum protocol specifics that you may want to look at to base your solution on: https://github.com/tkstanczak/nethermind/blob/master/src/Nethermind/Nethermind.Core/Crypto/EthereumSigner.cs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.