Getting Started

Assuming you have a substrate node already running, you are now ready to build your services and clients using the Ajuna SDK toolchain.

Template Installation

Install our .NET template with the following command:

dotnet new --install Ajuna.DotNet.Template

which makes dotnet new ajuna available.

Project Generation

Using a terminal of your choice, create a new directory for your project and execute the following command in that directory:

dotnet new sln
dotnet new ajuna \
   --sdk_version 0.1.27 \
   --rest_service AjunaExample.RestService \
   --net_api AjunaExample.NetApiExt \
   --rest_client AjunaExample.RestClient \
   --metadata_websocket ws://127.0.0.1:9944 \
   --force \
   --allow-scripts yes

which generates a new solution and a couple of .NET projects in your project directory. (A description for all command parameters can be found here)

.
β”œβ”€β”€β”€ .ajuna
β”œβ”€β”€β”€ .config
β”œβ”€β”€β”€ AjunaExample.NetApiExt
β”œβ”€β”€β”€ AjunaExample.RestClient
β”œβ”€β”€β”€ AjunaExample.RestClient.Mockup
β”œβ”€β”€β”€ AjunaExample.RestClient.Test
β”œβ”€β”€β”€ AjunaExample.RestService

Role of the Generated Projects

Before elaborating on each of the generated projects, let’s first talk about Ajuna.NetApi which is the basis that these projects built upon.

Ajuna.NetApi

Ajuna.NetApi is the basic framework for accessing and handling JSON-RPC connections and handling all standard RPC calls exposed by the rpc.methods() of every substrate node. It additionally implements Rust primitives and Generics as a C# representation like U8, BaseVec (Vec<>), or EnumExt (Rust-specific Enums).

Ajuna.NetApiExt

Since Ajuna.NetApi has no other types than the ones previously described; accessing a node’s storage or sending extrinsic would involve manually creating the necessary types. This is where the generated Ajuna.NetApiExt comes into play since it extends Ajuna.NetApi by exposing all the node-specific types, storage access, extrinsic calls, and more.

Ajuna.RestService

This service:

  • Connects to a node and subscribes to the global storage changes, which are then maintained in memory.

  • Offers a REST service (poll) that exposes all the storage information as REST.

  • Offers a subscription service (pub/sub) providing changes over a WebSocket.

The benefit of this approach is that this artifact is much more lightweight than the node itself and can therefore be scaled according to the needs of the consumers without putting any load on an RPC node except for one connection (per RestService instance) for the global storage subscription.

Ajuna.RestClient

This RestClient can be used in a C#, Unity, or any other application allowing it to access the information provided by the previously described RestService. Using the RestClient, one could subscribe to the node storage changes using the WebSocket or access the storage directly through the exposed REST service.

As you can see, we could launch any service or create any application on top of Substrate without any further knowledge except the library usage.

The generated projects contain everything you need to get started making excellent substrate services and clients in C# and the .NET framework.

Video Tutorial

You can also watch our short step-by-step tutorial that guides you through the entire process.

Last updated