To expand the other response, to provide offline transaction signing in Nethereum you can do the following:
First, you will need your private key, and sender address. You can retrieve the sender address from your private key using Nethereum.Core.Signing.Crypto.EthECKey.GetPublicAddress(privateKey);
if you only have the private key.
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);
You can see this example on the unit test
Or a "real" implementation on the Game sample
0x3078616263646566
is the hex representation of the UTF-8 encoding of the string "0xabcdef"
. "0"
is hex 30, "x"
is hex 78, and so on. Try passing in b'\xab\xcd\xef'
as the data, instead.
You can generate this byte string from hex with:
import codecs
raw_bytes = codecs.decode('abcdef', 'hex')
assert raw_bytes == b'\xab\xcd\xef'
It's also worth checking out the package ethereum-utils
for eth_utils.decode_hex()
and other useful tools.
Best Answer
The Nethereum does not support it directly but all versions of Parity wallet supports it and recent versions of geth also supports it, so we can send an RPC call directly without using any Nethereum RPC call. The RPC method in question is
eth_getRawTransactionByHash
.Like so
where the following helper classes have been used
If you are so unfortunate to use a node that does not support
eth_getRawTransactionByHash
(old geth versions), you can still get the raw hex using the following functions to construct the raw hex from available data.