- Console packages:
- id: Assert version: 4.2.1
- id: Nethereum.Web3 version: 2.0.1
Signing messages with Nethereum
Nethereum allows you to sign any type of data using Ethereum signature format. The following is a quick guide to signing with Nethereum.
First, we need to set our environment:
First, let's download the test chain matching your environment from https://github.com/Nethereum/Testchains
Start a Geth chain (geth-clique-linux\, geth-clique-windows\ or geth-clique-mac\) using startgeth.bat (Windows) or startgeth.sh (Mac/Linux). The chain is setup with the Proof of Authority consensus and will start the mining process immediately.
We then need to add Nethereum's Nuget package:
After that, we will need to add
using Nethereum.Web3; using Nethereum.Web3.Accounts; using Nethereum.Web3.Accounts.Managed; using Nethereum.Signer; using Nethereum.KeyStore; using System.Threading; using System.Threading.Tasks;
Signing a message offline
Signing a message allows to certify that a piece of data was signed by a specific sending account. A signed message proves the origin of a message without revealing the private key of its signer account.
The below shows how to sign an arbitrary
address declares the sender's address
var address = "0x12890d2cce102216644c59dae5baed380d84830c";
msg declares the content of the message itself, here it's a simple string.
var msg = "wee test message 18/09/2017 02:55PM";
privatekey declares the sender's address
var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
signer creates an instance of the
var signer = new EthereumMessageSigner();
signature evaluates to the signature itself: a string.
var signature = signer.EncodeUTF8AndSign(msg, new EthECKey(privateKey));
addressRec evaluates to the signer's address
var addressRec = signer.EncodeUTF8AndEcRecover(msg, signature);