Core 3.0 Plugin Development

Testers who previously created Plugins for Core are encouraged to migrate their Plugins to be functional with Core V3 to increase test coverage and report any pain points found during the migration process.

Prerequisites

Before developing a plugin you should make sure that you have read the following links.

All of the above are quintessential to building plugins that are easy to maintain and expand. If you don’t fully understand those you will end up with difficult to maintain code that will be hacky.

You should also take a look at our blog series for Core 3.0 that will talk you through the most important changes with some samples to give you an idea about the internals of core and how to leverage them to your advantage for plugins you are planning to build.

Basics

The most basic plugin consist of 3 files which are responsible for getting your plugin configured and running within core.

defaults.ts

This file contains all of the configuration defaults for your plugin. If you are planning to expose environment variables to configure your plugin we recommend that you use a unique prefix like VENDOR_ for your plugins to avoid collisions with other plugins. For example if your plugin is is @vendor/something then you should prefix your environment variables with VENDOR_SOMETHING_ to ensure they are unique.

1export const defaults = {
2 server: {
3 http: {
4 enabled: !process.env.CORE_API_DISABLED,
5 host: process.env.CORE_API_HOST || "0.0.0.0",
6 port: process.env.CORE_API_PORT || 4003,
7 },
8 https: {
9 enabled: process.env.CORE_API_SSL,
10 host: process.env.CORE_API_SSL_HOST || "0.0.0.0",
11 port: process.env.CORE_API_SSL_PORT || 8443,
12 tls: {
13 key: process.env.CORE_API_SSL_KEY,
14 cert: process.env.CORE_API_SSL_CERT,
15 },
16 },
17 },
18};

service-provider.ts

This file contains the service provider which is the heart of your plugin. It is responsible for preparing, starting and stopping your plugin.

1import { Providers } from "@arkecosystem/core-kernel";
2 
3import Handlers from "./handlers";
4import { Identifiers } from "./identifiers";
5import { preparePlugins } from "./plugins";
6import { Server } from "./server";
7import { DelegateSearchService, LockSearchService, WalletSearchService } from "./services";
8 
9export class ServiceProvider extends Providers.ServiceProvider {
10 public async register(): Promise<void> {
11 this.app.bind(Identifiers.WalletSearchService).to(WalletSearchService);
12 this.app.bind(Identifiers.DelegateSearchService).to(DelegateSearchService);
13 this.app.bind(Identifiers.LockSearchService).to(LockSearchService);
14 
15 if (this.config().get("server.http.enabled")) {
16 await this.buildServer("http", Identifiers.HTTP);
17 }
18 
19 if (this.config().get("server.https.enabled")) {
20 await this.buildServer("https", Identifiers.HTTPS);
21 }
22 }
23 
24 public async boot(): Promise<void> {
25 if (this.config().get("server.http.enabled")) {
26 await this.app.get<Server>(Identifiers.HTTP).boot();
27 }
28 
29 if (this.config().get("server.https.enabled")) {
30 await this.app.get<Server>(Identifiers.HTTPS).boot();
31 }
32 }
33 
34 public async dispose(): Promise<void> {
35 if (this.config().get("server.http.enabled")) {
36 await this.app.get<Server>(Identifiers.HTTP).dispose();
37 }
38 
39 if (this.config().get("server.https.enabled")) {
40 await this.app.get<Server>(Identifiers.HTTPS).dispose();
41 }
42 }
43}

index.ts

This file contains all the exports of your package. There are no mandatory exports besides the service provider which is required .

1export * from "./service-provider";

Questions

If there are any questions about plugin migrations from 2.0 to 3.0 you can open issue on the GitHub repository with reproduction steps and a link to your repository. An update skeleton with the basics can be found at https://github.com/ArkEcosystem/core-plugin-skeleton/tree/lel .

Last updated 2 years ago
Edit Page
Share: