Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
darkfriend77 edited this page Jul 31, 2021 · 6 revisions

Types

Types in the substrate net API are grouped into base types, enum types, and struct types, currently, no other type category exists.

All types inherit in the end from IType interface. For information on how to add types for an extension, please look in the extension readme.

Custom Type

Adding a custom type consist of two steps.

    1. Step Add the custom type as class inheriting from IType, or using one of the following abstract classes:
    1. Step Register your class as a GenericTypeConverter to the client.
var WEBSOCKETURL = "wss://xyz.node.com"; // or local node ws://127.0.0.1:9944
using var client = new SubstrateClient(new Uri(WEBSOCKETURL));
client.RegisterTypeConverter(new GenericTypeConverter<MogwaiStruct>()); // custom types
client.RegisterTypeConverter(new GenericTypeConverter<MogwaiBios>());  // custom types
await client.ConnectAsync(cancellationToken);

Base Types

Base types inherit BaseType and have a C# primitive or class as generic type added.

    public class U32 : BaseType<uint>

Enum Types

Adding simple enum types is simply done by inheriting from EnumType, and is handled by adding the specific enum type.

    public enum GameEventType
    {
        Default,
        Hatch
    }

If the enum has variants that involve parameters, you can choose to implement it as a structure or inheriting the ExtEnumType.

In the tests there is an application for both, check here.

Struct Types

Struct types inherit the StructType class and are considered as a full implementation of each field.

    public class DispatchInfo : StructType

Clone this wiki locally