I`m trying to convert this code to c#

const message = response.data.message;
const jsonProvider = new ethers.providers.JsonRpcProvider(RPC_URL)
const ethersSigner = new ethers.Wallet(privatekey, jsonProvider);

const signature = await ethersSigner.signMessage(message);

but so far with out any luck. I found that I could sign message using Nethereum EthereumMessageSigner but can`t find a way for it to use the right RPC address. For example:

var account = new Account(PRIVATE_KEY);
var web3 = new Web3(account, RPC_URL);

var signer = new EthereumMessageSigner();
var signature = signer.EncodeUTF8AndSign(message, new EthECKey(PRIVATE_KEY));

Is it even possible in C#? (I'm trying to sign message in Blast mainnet)

1 Answer 1


You don't need a RPC in order to sign, just a private key and a message (it's just cryptography). Keep in mind that signing is chain agnostic, once you sign a message with a private key it's valid on all the chains, in fact it's valid everywhere (even offchain). I recommend this article to learn what a signature is and how it really works under the hood.

You can use the following snippet to sign the message "message" with the hardcoded privatekey:

using System;
using Nethereum.Signer;

public class Program
    public static void Main()
        var signer = new EthereumMessageSigner();
        var signature = signer.EncodeUTF8AndSign("message", new EthECKey("0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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