visit
In this post we will get familiar with the architectural approaches that make blockchain application development almost like a walk in the park. We will address five simple, yet efficient software development approaches for blockchain applications. Each of them being supported with code samples and tutorials.
This is an introductory post, that will be followed by separate tutorials and workshops where we will build a fully working blockchain application.
We all know the sysadmin magic that had to be done in order to get a blockchain node running in the past. As a consequence a lot of developers got turned away by the sheer complexity of the development environment setup or missing cryptographic libraries and implementations. Luckily for all of us, our HERO — came along. Delivering the promise of seamless and easily customisable blockchain deployment in three simple steps.
Everything we learned in the field (meetings with organisations, PoC projects implementations, hackathons and workshops) combined with our expert knowledge has guided us towards building a product to enable easy and in a only a few minutes.All ARK based bridgechains are accompanied with free and open-source SDK’s, that enable you to jump right into application development and leave the blockchain protocol and sysadmin details to be taken care of by our automation tools and SDK implementations in more than 1. Feel free to join our friendly chat at and ask for help and guidance in our #help channel.With ARK’s modular core our distributed-servers/nodes running in the background translate into containers — where you can deploy your own blockchain based applications and you don’t need to worry about consensus protocol or peer-to-peer network mechanics — it’s a protocol thing, just like TCP/IP, well a lot more complex; but it’s there running in the background, delivering security, trust and immutability — delivering the promise of blockchain.
This gives us the power to create agnostic blockchain applications, that can be run within any blockchain based on ARK Core technology. By developing applications on our plug-able core technology developers can build blockchain agnostic applications, target bigger audiences and provide cross-chain compatible solutions.
This introduces and further strengthens the role of the ARK Ecosystem, by bringing in new interchain monetization services allowing businesses to fully exploit and research new crypto driven business models. Our blockchain application development approach is closing the gap between traditional development practices by bridging the concept of software libraries and blockchain development.
Ok, so what now? Now we can deploy a module, like in most web applications — but where is “the blockchain/the ledger” and how do we use it?
Don’t worry, we got you covered with ARK Logic — Enabling your application to run in a modular fashion on the distributed network. Your application life cycle is maintained by our Core and is inherited by the overall life cycle of a blockchain node. A strong benefit of plug-able applications/modules is having access to the blockchain mechanics in a very simple and developer friendly way. Blockchain interaction is something we take very seriously, and we deliver this via the following approaches.
1. Interacting with the blockchain state
The core-blockchain package is the central entity around which everything revolves. It provides a state-machine that controls the state of your node and switches between states to sync, rollback or recover from a fork. It holds all of the information that is important to know when you want to see what the current state of your blockchain node is. Do not trust the database, trust the in-memory data it exposes, as it’s updated in real-time.import { app } from "@arkecosystem/core-container";
const blockchain = app.resolvePlugin("blockchain");
async function callBlockchainMethods() {
// Check if the blockchain is fully synced
blockchain.isSynced();
// Get the last block we've received
blockchain.getLastBlock();
// Get the height of the last block we've received
blockchain.getLastHeight();
// Get the last block we've downloaded
blockchain.getLastDownloadedBlock();
// Get a list of events the blockchain emits
blockchain.getEvents();
}
callBlockchainMethods();
Full Tutorial:
2. Interacting with the database
You can access blocks and transactions in a very simple and efficient way by using the database plugin.import { app } from "@arkecosystem/core-container";
const database = app.resolvePlugin("database");
async function callDatabaseMethods() {
// Get a block from the database by its id
await database.getBlock("some block id");
// Skip the first 100 blocks, grab the next 100
await database.getBlocks(100, 100);
// Grab blocks at height 1, 5 and 10
await database.getBlocksByHeight([1, 5, 10]);
// Get all blocks that have been forged in round 10
await database.getBlocksForRound(10);
// Get the last block we've received
await database.getLastBlock();
// Get the last 10 blocks we've received
await database.getRecentBlockIds();
// Get a transaction from the database by its id
await database.getTransaction("some transaction id");
}
callDatabaseMethods();
Full Tutorial:
3. Use events to listen and react to changes
Core provides a package called core-event-emitter which exposes an instance of the Node.js EventEmitter. A common use-case is that your module will listen to events that core emitted in order to process the data for monitoring. Your module can also emit events that can be listened to by other plugins (or your own for internal use).import { app } from "@arkecosystem/core-container";
import { EventEmitter, Logger } from "@arkecosystem/core-interfaces";
const logger = app.resolvePlugin<Logger.ILogger>("logger");
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter");
emitter.on("forger.missing", delegate => {
// This will be a wallet object that contains information like the address, username, public key, votes, etc.
logger.warn(`${delegate.username} just missed a block.`);
// Here we could for example send a slack notification that we just missed a block
});
Full Tutorial:
4. Add new API endpoints via customisable HTTP server running within core nodes
A common use-case for a plugin is that you process some data from within core and want to make use of that data with an external application. The easiest way to do this is through an HTTP server that exposes an API from which you request the data.import { createServer, mountServer } from "@arkecosystem/core-http-utils";
export async function startServer(config) {
const server = await createServer({
host: config.host,
port: config.port
});
server.route({
method: "GET",
path: "/",
handler(request, h) {
return "Hello World";
}
});
return mountServer("My HTTP Server", server);
}
startServer({ host: "localhost", port: 8000 });
Full Tutorial:
5. Pack and distribute your blockchain application as a module
The last piece of the puzzle is packing everything into a module and distributing it to your blockchain network. Our plugins are modular by design, meaning the concepts described above will all be already developed inside your own module. Having your own module, enables you to publish it to the largest package repository — npm, thus making it available to everyone.import { Container } from "@arkecosystem/core-interfaces";
import { LogManager } from "@arkecosystem/core-logger";
import { defaults } from "./defaults";
import { PinoLogger } from "./driver";
export const plugin: Container.PluginDescriptor = {
pkg: require("../package.json"),
defaults,
alias: "logger",
extends: "@arkecosystem/core-logger",
async register(container: Container.IContainer, options) {
const logManager: LogManager = container.resolvePlugin("log-manager");
await logManager.makeDriver(new PinoLogger(options));
return logManager.driver();
}
};
Full Tutorial:
Using the above mentioned concepts will make your blockchain application development a breeze and it lowers the gap between enterprise application developers and crypto developers. We encourage you to test these approaches and start building your first blockchain application.Part two of this Blockchain Application Development series will cover introduction to developing custom transaction types with our Generic Transaction Interface (GTI). The basic premise of GTI is to provide an easy way to implement and include new transaction types in your blockchain without the need to modify more complex parts of the Core. It can be as simple as including pre-defined templates depending on the use case of the blockchain or re-using already present types and modify their parameters to introduce new ones. Developing custom transaction types enables you to add your own custom logic and data, validate it via existing consensus mechanisms and store it on-chain.
After that you will master all the skills needed to build blockchain applications with ARK Logic. We will leverage that and build a fully functional blockchain application.Read our new 2019 , Follow us on social media ( | | ), join our community ( | ) and stay tuned to our blog on and on .