# Register new Chain

{% hint style="success" %}
Up to date
{% endhint %}

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:

```json
{
    "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:

* .NET 6.0 - <https://dotnet.microsoft.com/en-us/download/dotnet/6.0>
* Substrate.Net.Toolchain - <https://github.com/SubstrateGaming/Substrate.NET.Toolchain>.

{% hint style="info" %}
The script is designed to be run on linux. Use WSL or update the script to be compatible with your OS.
{% endhint %}

## Register the chain info

Go to `PlutoFramework/Constants/Endpoints.cs`.

Add the `EndpointEnum`:

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

Add the genesis hash to the `HashToKey` Dictionary:

```csharp
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`:

```csharp
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
};
```

## Link the Generated Chain Representation to your app

Add the generated chain .csproj to your app solution:

<figure><img src="/files/tPXuPzLVMiGWirSb005L" alt=""><figcaption><p>Solution -> Add -> Existing Project...</p></figcaption></figure>

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

<figure><img src="/files/6xYmcjdLoL7EDp4CX9Gq" alt=""><figcaption><p>PlutoFramework.Model -> Add -> Project Reference...</p></figcaption></figure>

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

```csharp
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`:

```csharp
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),
    };
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://plutolabs.gitbook.io/plutoframework/make-your-application/register-new-chain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
