Introduction

Overview

Transactions

Installation

Security

Deployment

Development Guides

Testing

Releases

Support

Modeling dApp Structures

Modules are very simple to write. At their core they are an object with a register property, that is a function with the signature async function.

Everything we use inside ARK core is built with modules. To learn more about modules and their structure follow the source code of existing modules within core.

GitHub learning repository has a template project available here . You can create a new module by creating a new GitHub repository and selecting the correct template: learn-ark/dapp-core-module-template.

Package properties

The module properties are set in the package.json file in the root of you core module.

  • name the module name
  • version the module version
  • arkecosystem:
    • core:
      • alias: the module alias
      • dependencies: the module dependencies
      • required: is module required

Service Provider

import { Container, Contracts, Providers } from "@arkecosystem/core-kernel";
import { DappManager } from "./manager";

const DappManagerIdentifier = Symbol.for("DappManager");

export class ServiceProvider extends Providers.ServiceProvider {
    public async register(): Promise<void> {
        this.app.get<Contracts.Kernel.Logger>(Container.Identifiers.LogService).info(`Loading dapp`);

        this.app.bind<DappManager>(DappManagerIdentifier).to(DappManager).inSingletonScope();
    }

    public async boot(): Promise<void> {
        this.app.get<Contracts.Kernel.Logger>(Container.Identifiers.LogService).info(`Booting dapp`);

        this.app.get<DappManager>(DappManagerIdentifier).start({});
    }

    public async dispose(): Promise<void> {
        this.app.get<Contracts.Kernel.Logger>(Container.Identifiers.LogService).info(`Disposing dapp`);

        this.app.get<DappManager>(DappManagerIdentifier).stop();
    }
}

Registration

Module needs to be registered in order to be picked up by the core engine. Looking at the source code above each core module must have the register method implemented. This method is called from the application container.

public async register(): Promise<void> {
    this.app.get<Contracts.Kernel.Logger>(Container.Identifiers.LogService).info(`Loading dapp`);

    this.app.bind<DappManager>(DappManagerIdentifier).to(DappManager).inSingletonScope();
}

Take a look on Service Providers to learn more about it.

Let’s head over to the next section, where we will learn how to write our own dApp in a few minutes, just by following our dApp core module template repository.

2021 © ARK.io | All Rights Reserved
An ARK.io Product