Register new Chain

Here are the steps needed to make to add a new chain. Please, do not skip any of them!

Add the chain info inside of the chains.json file:

{
    "name": "Chain name",
    "websocket": "wss://yourendpoint.io"
}

Afterwards, you can run the following script:

./generator.sh <Chain name>

Before running the script, you might need to install the following:

The script is designed to be run on linux. Use WSL or update the script to be compatible with your OS.

Register the chain info

Go to PlutoFramework/Constants/Endpoints.cs.

Add the EndpointEnum:

public enum EndpointEnum
{
    Polkadot,
    Kusama,
    // ...
    YourChain
}

Add the genesis hash to the HashToKey Dictionary:

public static readonly ReadOnlyDictionary<string, EndpointEnum> HashToKey = new ReadOnlyDictionary<string, EndpointEnum>(new Dictionary<string, EndpointEnum>()
{
    { "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3", EndpointEnum.Polkadot },
    { "0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe", EndpointEnum.Kusama },
    // ...
    { "GenesisHashOfYourChain", EndpointEnum.YourChain },
});

Add the your chain details to GetEndpointDictionary:

public static readonly ReadOnlyDictionary<EndpointEnum, Endpoint> GetEndpointDictionary = new ReadOnlyDictionary<EndpointEnum, Endpoint>(new Dictionary<EndpointEnum, Endpoint>()
{
    { EndpointEnum.Polkadot, new Endpoint
    {
        Name = "Polkadot",
        Key = EndpointEnum.Polkadot,
        URLs = new string[5] { "wss://polkadot-rpc.dwellir.com", "wss://polkadot-public-rpc.blockops.network/ws", "wss://rpc.ibp.network/polkadot", "wss://polkadot.api.onfinality.io/public-ws", "wss://polkadot.public.curie.radiumblock.co/ws" },
        Icon = "polkadot.png",
        DarkIcon = "polkadot.png",
        CalamarChainName = "polkadot",
        SubSquareChainName = "polkadot",
        SubscanChainName = "polkadot",
        Unit = "DOT",
        Decimals = 10,
        SS58Prefix = 0,
        ChainType = ChainType.Substrate,
        ParachainId = new ParachainId
        {
            Relay = RelayChain.Polkadot,
            Chain = Chain.Relay,
            Id = null,
        }
    } },
    
    // ...
    
    // Add your chain here
};

Add the generated chain .csproj to your app solution:

Solution -> Add -> Existing Project...

Add the reference to your chain. Select PlutoFramework.Model -> Add -> Project Reference... and select your chain project.

PlutoFramework.Model -> Add -> Project Reference...

Now add your chain to the SubstrateClientExt which can be found in PlutoFramework.Model/AjunaExt/SubstrateClientExt.cs:

private SubstrateClient GetSubstrateClient(EndpointEnum endpointKey, Uri websocket)
{
    return endpointKey switch
    {
        EndpointEnum.Polkadot => new Polkadot.NetApi.Generated.SubstrateClientExt(websocket, ChargeTransactionPayment.Default()),
        EndpointEnum.PolkadotAssetHub => new PolkadotAssetHub.NetApi.Generated.SubstrateClientExt(websocket, ChargeTransactionPayment.Default()),
        // ...
        
        EndpointEnum.YourChain => new YourChain.NetApi.Generated.SubstrateClientExt(websocket, ChargeTransactionPayment.Default()),
        
        _ => new SubstrateClient(websocket, ChargeTransactionPayment.Default()),
    };
}

Lastly, add your chain to the EventsModel which can be found in PlutoFramework.Model/EventsModel.cs:

public static async Task<ExtrinsicDetails> GetExtrinsicEventsForClientAsync(
    this SubstrateClientExt substrateClient,
    uint? extrinsicIndex,
    string? eventsBytes,
    BigInteger blockNumber,
    CancellationToken token
)
{
    return substrateClient.Endpoint.Key switch
    {
        EndpointEnum.Polkadot => await GetExtrinsicEventsAsync<Polkadot.NetApi.Generated.Model.polkadot_runtime.EnumRuntimeEvent>(substrateClient, extrinsicIndex, eventsBytes, blockNumber, token),
        EndpointEnum.PolkadotAssetHub => await GetExtrinsicEventsAsync<PolkadotAssetHub.NetApi.Generated.Model.asset_hub_polkadot_runtime.EnumRuntimeEvent>(substrateClient, extrinsicIndex, eventsBytes, blockNumber, token),
        // ...
        EndpointEnum.YourChain => await GetExtrinsicEventsAsync<YourChain.NetApi.Generated.Model.your_chain_runtime.EnumRuntimeEvent>(substrateClient, extrinsicIndex, eventsBytes, blockNumber, token),
        
        _ => await GetExtrinsicDetailsAsync(substrateClient, extrinsicIndex, eventsBytes, blockNumber, token),
    };
}

Last updated