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.

1. 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.

2. Setup

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

Note that this repository is not yet available and will become available with ARK Core V2 codebase going public on June 14th 2018.



git clone

cd your-plugin-name

yarn install bashgit clone https://github.com/ArkEcosystem/core-plugin-skeleton your-plugin-namecd your-plugin-nameyarn install

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.



"name": "

"description": "This plugin provides X for ARK Core 2.0",

} "name": " @vendor/your-plugin-name ","description": "This plugin provides X for ARK Core 2.0",

3. Development

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

3.1. 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.



const util = require('util')

const container = require('

const logger = container.resolvePlugin('logger') const twilio = require('twilio')const util = require('util')const container = require(' @arkecosystem/core-container ')const logger = container.resolvePlugin('logger') module.exports = class Twilio {

constructor(options) {

this.client = twilio(options.accountSid, options.authToken)

this.options = options

} async sendMessage(delegate, block) {

try {

await client.messages.create({

body: util.format(this.options.body, delegate.username, block.height),

from: this.options.from,

to: this.options.to

}) logger.info(`[Monitor] An SMS was send with the ID ${message.sid} for a missed block at height ${block.height}.`)

} catch (error) {

logger.info(`[Monitor] Failed to send an SMS. Reason: ${error.message}`)

}

}

}

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.

3.2. 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.

'use strict'

const emitter = container.resolvePlugin('event-emitter') const container = require(' @arkecosystem/core-container ')const emitter = container.resolvePlugin('event-emitter') class Listener {

setUp(options, twilio) {

emitter.on('forging.missing', data => {

if (data.delegate.publicKey === options.publicKey) {

twilio.sendMessage(data.delegate, data.block)

}

})

}

} module.exports = new Listener()

3.3. 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.

'use strict' const listener = require('./listener')

const Twilio = require('./twilio') exports.plugin = {

pkg: require('../package.json'),

register: async (container, options) => {

logger.info('[Monitor] Waiting for Missed Blocks') listener.setUp(options, new Twilio(options.twilio))

}

}

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.

3.4. 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 on steemit for more details in the upcoming days as we get closer to v2 going public!