Docs
Configuration

Configuration

Your app-chain can be configured at three different levels: runtime, chain and client. Firstly we start with the overall runtime configuration, specifying the definition/configuration of your runtime module layout:

packages/chain/src/runtime.ts
import { Balance } from "@proto-kit/library";
import { Balances } from "./balances";
import { ModulesConfig } from "@proto-kit/common";
 
export const modules = {
  Balances,
};
 
export const config: ModulesConfig<typeof modules> = {
  Balances: {
    totalSupply: Balance.from(10_000),
  },
};
 
export default {
  modules,
  config,
};
 

Server & client configuration

The runtime configuration above is then used to define app-chain configurations for both client and server side app-chains. Keep in mind that configuration for the rest of the app-chain, namely the protocol and the sequencer is provided implicitly behind the scenes.

chain.config.ts is used by Protokit's CLI to start a server-side app-chain, while client.config.ts is used by the Protokit SDK to connect to the server-side app-chain via e.g. GraphQL.

packages/chain/src/chain.config.ts
import { LocalhostAppChain } from "@proto-kit/cli";
import runtime from "./runtime";
 
const appChain = LocalhostAppChain.fromRuntime(runtime.modules);
 
appChain.configure({
  ...appChain.config,
  Runtime: runtime.config,
});
 
// TODO: remove temporary `as any` once `error TS2742` is resolved
export default appChain as any;
packages/chain/src/client.config.ts
import { ClientAppChain } from "@proto-kit/sdk";
import runtime from "./runtime";
 
const appChain = ClientAppChain.fromRuntime(runtime.modules);
 
appChain.configurePartial({
  Runtime: runtime.config,
});
 
export const client = appChain;