Core Concepts
Add Signature
Learn about Signatures on the official Solana documentation
public class AddSignatureExample : IExample
{
private static readonly IRpcClient rpcClient = ClientFactory.GetClient(Cluster.TestNet);
private const string MnemonicWords =
"route clerk disease box emerge airport loud waste attitude film army tray " +
"forward deal onion eight catalog surface unit card window walnut wealth medal";
public void Run()
{
Wallet.Wallet wallet = new Wallet.Wallet(MnemonicWords);
Account fromAccount = wallet.GetAccount(10);
Account toAccount = wallet.GetAccount(8);
RequestResult<ResponseValue<BlockHash>> blockHash = rpcClient.GetRecentBlockHash();
Console.WriteLine($"BlockHash >> {blockHash.Result.Value.Blockhash}");
TransactionBuilder txBuilder = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(fromAccount)
.AddInstruction(SystemProgram.Transfer(fromAccount.PublicKey, toAccount.PublicKey, 10000000))
.AddInstruction(MemoProgram.NewMemo(fromAccount.PublicKey, "Hello from Sol.Net :)"));
byte[] msgBytes = txBuilder.CompileMessage();
byte[] signature = fromAccount.Sign(msgBytes);
byte[] tx = txBuilder.AddSignature(signature)
.Serialize();
Console.WriteLine($"Tx base64: {Convert.ToBase64String(tx)}");
RequestResult<ResponseValue<SimulationLogs>> txSim = rpcClient.SimulateTransaction(tx);
string logs = Examples.PrettyPrintTransactionSimulationLogs(txSim.Result.Value.Logs);
Console.WriteLine($"Transaction Simulation:\n\tError: {txSim.Result.Value.Error}\n\tLogs: \n" + logs);
RequestResult<string> firstSig = rpcClient.SendTransaction(tx);
Console.WriteLine($"First Tx Signature: {firstSig.Result}");
}
}