Adding a Substrate Network to Enkrypt

Getting Started

Set up your development environment

  1. Create a fork of the repository

  2. Clone the fork locally

  3. In the root directory run the following:

yarn --frozen-lockfile
yarn build:all
yarn watch-extension

You will now have your fork ready to go and your project is watching for changes to Enkrypt.

Add your network's name and platform

Navigate to packages/types/src/networks.ts and add your network's name to the NetworkNames enum.

If your network has a Coingecko platform ID you can add that to CoingeckoPlatform as well. To find your network's coingecko platform run the following in your teminal:

curl https://api.coingecko.com/api/v3/asset_platforms

Note: After adding your network to networks.ts you will need to run yarn build:all again.

Create a network file

Navigate to packages/extension/src/providers/polkadot/networks and create a file with the name [network-ticker].ts.

In your new network file import SubstrateNetwork and SubstrateNetworkOptions and create a variable for your network's configuration.

import { SubstrateNetwork, SubstrateNetworkOptions } from "../types/substrate-network";

const netOptions: SubstrateNetworkOptions = {
    ...
};

The SubstrateNetworkOptions interface takes this form:

export interface SubstrateNetworkOptions {
  name: NetworkNames;
  name_long: string;
  homePage: string;
  blockExplorerTX: string;
  blockExplorerAddr: string;
  isTestNetwork: boolean;
  currencyName: string;
  icon: string;
  decimals: number;
  prefix: number;
  node: string;
  coingeckoID?: string;
  coingeckoPlatform?: CoingeckoPlatform;
  genesisHash: string;
  knownTokens?: KnownTokenDisplay[];
  existentialDeposit?: BN;
  activityHandler: (
    network: BaseNetwork,
    address: string
  ) => Promise<Activity[]>;
  assetHandler?: (
    network: SubstrateNetwork,
    address: string | null,
    knownTokens?: KnownTokenDisplay[]
  ) => Promise<BaseToken[]>;
}

For a basic network integration the only required fields are name, name_long, homePage, blockExplorerTX, blockExplorerAddr, chainID, currencyName, node, icon, isTestNetwork, prefix, genesisHash, and activityHandler.

For further customization take a look at other networks that are already added to Enkrypt.

For node use a wss URL when possible.

For blockExplorerTx, and blockExplorerAddr you should put the URL with the template string [[txHash]] and [[address]] where they would go in the URL respectively.

Then create a new SubstrateNetwork and export it.

const net = new SubstrateNetwork(netOptions);

export default net;

And finally in packages/extension/src/providers/polkadot/networks/index.ts add your network to the exported networks.

Your network should now show up in the manage networks screen!

Adding Activity Handler

Having an activity handler for your network is mandatory and will give users a good experience. Activity handler is responsible for showing past activity of the user on activity tab We already implemented a activity handler for subscan api. If you already part of subscan

import { subscanActivity } from "../libs/activity-handlers";
const netOptions: SubstrateNetworkOptions = {
    ...
    activityHandler: wrapActivityHandler(subscanActivity),
};

and then add the subscan api link to

packages/extension/src/providers/polkadot/libs/activity-handlers/providers/subscan/configs.ts#L3

However, if you dont have an api compatible with subsca you have to manually create one that can return transaction history for the user, it should follow the following type.

export type ActivityHandlerType = (
  _network: BaseNetwork,
  _address: string
) => Promise<Activity[]>;

Some sample handlers are located at

packages/extension/src/providers/polkadot/libs/activity-handlers/providers

if you dont have any api to get all user assets, you can simply return and empty array. That way Enkrypt will only display user activity happened inside the Enkrypt

const netOptions: SubstrateNetworkOptions = {
    ...
    activityHandler: wrapActivityHandler(() => Promise.resolve([])),,
};

Adding an Asset Handler

Having an asset handler for your network is optional but better to have it since it'll give an amazing experience to the user. Specially if you have different tokens in your substrate chain.

For furthen information on how to implement an asset handler, please checkout the Acala ormlHandler

packages/extension/src/providers/polkadot/networks/acala/acala.ts#L32

Last updated