Creating a dApp Module

Step 1: Prepare Your Local Development Environment

Many components are required to have a proper environment setup for the development of your ARK Core module. You can view instructions on how to setup your development environment here:

Installation - Introduction

Step 2: Create A New Module From A Template

Information

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

After your repository has been created, you can add it as a submodule within the core/plugins folder and start changing the defaults.

1cd plugins/
2git submodule add -f https://github.com/your-username/your-core-plugin-repo-name

1.1 Module Configuration

We need to make some changes to the project first. Make sure to modify the default names for the files:

The name of our module is @vendorname/your-dapp-name. Make sure to change the name in your package.json accordingly. It is recommended to scope your packages with a prefix like @your-vendor/ to distinguish it from other npm packages. Check https://docs.npmjs.com/misc/scope for more information.

1.2 Adding Module Dependencies

If your package relies on any dependencies you should install them via lerna add the plugin you are developing.

1lerna add dependency-name --scope=@vendor/demo-plugin --dev

Once everything is set up and configured, we can move on to developing the plugin.

Step 3: Module Registration Within Network Configuration

Information

In order to make sure that your plugin is registered and loaded when Core Node starts, you will need to modify the app.json file related to the current network run mode.

Since, we are running a local development environment, we will need to edit the Testnet configuration folder (core/packages/core/bin/config/testnet/app.json) and add our module name to the list of loaded modules. This is also a good place to set up the module’s default properties, defined in the default.ts file in our module’s root folder.

app.json

1module.exports = {
2 "core": {
3 "plugins": [
4 // Order is IMPORTANT!
5 // Modules are loaded in the same order as they are listed
6 {
7 "package": "@arkecosystem/core-logger-pino"
8 },
9 {
10 "package": "@arkecosystem/core-state"
11 },
12 {
13 "package": "@arkecosystem/core-database"
14 },
15 {
16 "package": "@arkecosystem/core-transactions"
17 },
18 ...
19 ... // other core plugins and their settings
20 ...
21 {
22 "package": "@your-vendor/your-module-name-from-package",
23 "options": {
24 // Here we can overwrite the module properties that are defined in defaults.ts file
25 enabled: true,
26 host: "0.0.0.0",
27 port: 8081,
28 ...
29 ...
30 }
31 }
32 ]
33 }
34};

Warning

Make sure to run yarn setup from the core root folder when you change or add code to core/plugins. This command takes a long time, just let it finish.

After yarn setup completes you should see the following output:

1lerna success - @arkecosystem/core-api
2lerna success - @arkecosystem/core-blockchain
3lerna success - @arkecosystem/core-cli
4lerna success - @arkecosystem/core-database
5lerna success - @arkecosystem/core-forger
6lerna success - @arkecosystem/core-kernel
7lerna success - @arkecosystem/core-logger-pino
8lerna success - @vendorname/dappname # Your Module

Every plugin that is being registered in this file will be automatically loaded one after another to guarantee that all required data is available, so make sure your custom modules are placed in the right spot.

Step 4: Running Your dApp

Start local blockchain with Testnet running on your developer computer. Follow steps defined in here:

Development - Launching a Testnet

If you already have compiled and running core, just go to core/packages/core and run the yarn full:testnet command.

After the local Testnet starts, the log should show that dApp Module was loaded and run. Console output should look like this (if you haven’t changed the source code from the template):

1[2020-10-22 11:13:27.161] INFO : Loading dApp
2[2020-10-22 11:13:27.161] INFO : Booting of dApp

Success

Congratulations. Your first distributed blockchain application is loaded, running and compatible with any ARK Core based blockchain.

Feel free to look at other Core packages that expose important Core Platform building blocks to work with. Your newly developed classes can extend this class and gain access to:

  • wallets and state
  • transaction pool
  • blockchain protocol
  • events
  • database
  • api
  • logger
  • well…actually any core-module :)
Last updated 2 years ago
Edit Page
Share: