Setting Up New Plugins in ARK Core v2 (Example)

in #blockchain6 years ago

If you have followed ARK for any amount of time, you have probably heard ARK referred to as the "WordPress of Blockchains". This is a bold statement in an industry full of ever more extravagant claims and we want to show that ARK isn't just hype.

In Core V2, "WordPress of Blockchains" isn't just a tagline, it is an actual working system ready for deployment. Our modular plugin system is easy to configure, easy to modify, easy to implement, and easy to make. One of our goals is making blockchains easier for everyone and our modular plugin system is a major step towards achieving that goal.

As we near the ARK Core V2 release we wanted to give you a simple example of how to build plugins in the new ARK Core. The plugin system for ARK Core V2 will be something totally new and one of the first solutions (not a 2nd layer solution, but native binding to the core) to offer such a service to developers and other enthusiasts. Our new modular plugin system will offer a new era in customizable blockchain solutions powered by the all new ARK core. Users will be able to add, remove, or replace new or existing plugins directly to their ARK blockchains without breaking or jeopardizing the main ARK network or its security.

Introduction

In this post we will go over how you can setup a new plugin, develop and register it in the ARK core. In this example our plugin will send you an SMS(text message) to alert you if your node is down or missing blocks.

Setup

To get started we will clone the core-plugin-skeleton which provides you with a setup we recommend for all core plugins.

Note: For the original story please visit the ARK Blog to copy paste, also note that this repository is not yet available and will become available with ARK Core V2 codebase going public on June 14th 2018.

Now that we have the repository set up, open the package.json and adjust the name and description to explain what your plugin is about.

Development

The repository should now be configured and all dependencies installed so we can begin to set up and implement our monitoring plugin.

Setting up the Twilio Client

Our first step will be to implement the Twilio Client which will be responsible for sending a text message every time we miss a block so we can react and take care of the server.

The container gives us access to all ARK Core plugins that are active. In most cases your plugin will need access to config, logger, event emitter or the database. The sendMessage method accepts a delegate and block parameter which we will use to build our message.

Setting up the Event Listener

Now that we have the Twilio Client implemented we can set up our Event Listener. We will listen to the forging.missing event which will provide us an object that will contain the delegate and block arguments we need for sendMessage. We will only call sendMessage if the configured delegate matches the delegate that just missed a block.

Setting up the Plugin

Now that we implemented the Twilio Client and Event Listener we need to fill out the lib/index.js which serves as the entry point of our plugin by providing things like a name, version and functions to set up and tear down the plugin.

The register function will be used by @arkecosystem/core-container to set up your plugin and expose it to ARK Core. In this example we use the register method to set up your event listener and Twilio messenger.

Note: If your plugin runs anything like an express server remember to shut it down in the deregister function which will be used by @arkecosystem/core-container to tear down your plugin.

Registering the Plugin

Now that the plugin is developed we can go ahead and register it within ARK Core. To do that open ~/.ark/config/plugin.js and append your plugin and its configuration to it.

This is it — simple as that. Restart your node process and test your newly developed plugin!

With v2 just around the corner (don’t forget we will be releasing ARK Core codebase for DevNet testing on the 14th June 2018 and will also be running a special Pull Request bounty on Core v2 repo that will pay x2 for each merged PR on ARK Core repository ($20 per merge) )— if you haven’t yet please give this a read : https://blog.ark.io/ark-core-v2-codebase-and-devnet-release-date-21b93cc372bb) we’ll also introduce our newest Readme.io docs that will cover all of this and much much more under our new central documentation resource!

Follow us on social media ( Twitter | Facebook | Reddit ) and stay tuned to our blog on medium and here on steemit for more details in the upcoming days as we get closer to v2 going public!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63592.23
ETH 2551.58
USDT 1.00
SBD 2.75