C# SDK

Let's generate a C# SDK for KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of and interact with it. See section SDK generation for the details about this contract. The C# SDK relies on the Netezos library for forging and signing operations.

Import a KT1 from the Tezos blockchain

To generate the SDK of the contract in the current directory, run:

factori import kt1 . KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of \
    --csharp \
    --name my_contract \
    --network ghostnet \
    --force

Compile deps and SDK

You need to have dotnet and the Netezos package installed. For resources, look at:

  • Dotnet
  • https://netezos.dev/
  • https://github.com/baking-bad/netezos.

now initiate the C# project and cleanly format the generated code:

make csharp-init
make format-csharp

You are ready to use the C# SDK!

Hello world example

First, you may want to have a look at the content of src/csharp_sdk/ directory.

ls src/csharp_sdk/

Edit the file src/csharp_sdk/Program.cs with the following content:

using static Blockchain.Identities;

async static Task main()
{
    var hello_kt1 = "KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of";

    var ophash = await my_contract.Functions.CallHello(aliceFlextesa, hello_kt1, "Hello from C#", 1000000, 100000, 30000, 1000000, "ghostnet", false);
    Console.WriteLine($"A hello operation is sent to a node. Its hash is: {ophash}");
    Console.WriteLine("Waiting for its inclusion in a block ...");
    await Task.Delay(15000); // wait 15 seconds
    Console.WriteLine($"Check the status of your operation: https://ghostnet.tzkt.io/{ophash}");
}

await main();

To run it, simply run:

dotnet run --project src/csharp_sdk/

If everything goes well, you should see your transaction at: https://ghostnet.tzkt.io/KT1Fjiwsmo49yM7jch6KG4ETLFkatF3Qj8of