This article was originally written by Mika Hyttinen. Medium link: https://firstname.lastname@example.org
If some of my readers don’t know this yet, Cellframe is a third generation blockchain platform which allows you to create blockchain services/solutions with it’s SDK. Cellframe also packs some interesting core features:
- 2-level sharding
- post-quantum cryptography (from NIST PQC Round 3 submissions)
- P2P cross-chain operations
And much much more.
Cellframe and it’s Python SDK allows you to write dApps, or actually t-dApps (truly decentralized apps) for the Cellframe ecosystem. It also allows you to write just simple plugins for the Cellframe node.
There are probably many reasons why Cellframe chose Python as the default language for their SDK, but i’ll give here few reasons why I personally think they made this choice:
- Keeping it simple, Python is the world’s most popular programming language.
- Python is easy to learn, easy to use and it has tons of ready to use libraries available to install with Python package installer.
- And as Cellframe is written in C, Integrating Python to C based software is solid choice.
Building a simple plugin with Cellframe Python SDK
First of all, you should have Cellframe Python SDK installed. Easiest way to get things going is to probably just install Cellframe node. If you have Raspberry Pi 3/4 laying around, you can use my Raspberry Pi tutorial for your node installation. In that particular tutorial I also explained how to correctly make Cellframe node to load plugins as you need to edit configuration file before loading the plugins is possible.
If you are running Windows, you can install Cellframe Dashboard as it has Cellframe node built-in. The path for configuration file in Windows is %SystemDrive%\Users\Public\Documents\cellframe-node\etc
Understanding the structure of plugin files and folders
If you read my earlier tutorial, the default path for plugins is
/opt/cellframe-node/var/lib/plugins. By default, that particular directory is missing from that path so feel free to create the directory
plugins by yourself.
When you have created the plugins directory, it’s time to create another directory inside plugins. In this example, we’re using
tutorial, you need to have two files. One file is the plugin itself (in this example we’ll use
tutorial.py ) and the second file is
manifest.json . This is the current directory and file structure after making all the necessary files:
manifest.json, you specify basic metadata about your plugin such as the name, version and description. You can also declare if this current plugin has dependencies of other plugins. Typical
manifest.json looks something like this:
description keys must have a string values. The
name value must match the name of the plugin and the name of the directory. The
author values specifies the plugin version and plugin author. The
dependencys ² key must have a array value which contains strings with plugin names. If the specified plugins are not installed, then this plugin will not be launched. The
description value specifies a short description of the plugin.¹
tutorial.py (or whatever you may want to call it) is the plugin which runs when you start Cellframe node. A skeleton for Cellframe node plugin could look something like this:
When starting the node service, the
init functions of the python script of each plugin will be called. When stopping the node service, the
deinit functions will be called.
Let’s create a simple plugin!
Let’s start this series of articles with a simple “Hello World!” plugin tutorial.
Cellframe Python SDK allows you to add your own commands, which you can execute with the
First we need to study how all this works and look at their Wiki for
cmdItemCreate() method takes 4 arguments:
name: Name of the command
callbackFunction: Runs a function when command is called
doc: Short description of the command
docEx: Long description of the command
setReplyText() method takes 2 arguments:
replyText: String that is returned when command is called
idStrReply: must be a parameter idStrReply passed to the callback function.
So after we add this to our plugin, it should look something like this:
As the second argument is the handler function, we need to add a function to our plugin which is called when you run helloworld -command:
So after adding that, the finished plugin looks something like this:
If you don’t have the plugin placed in your plugins folder yet, you may move it there now. After that, just restart your node and fire up your terminal/Powershell etc. and type in cellframe-node-cli help , you should then be able to see our helloworld command in the list of commands:
So to use that command, just type in cellframe-node-cli helloworld and:
So there you have it. First simple plugin for your Cellframe node!
In the next article we will get back to our node installation series, this time we will be covering Windows (different type of installations, recommendations etc.).
When I’ll get back to the SDK, we will be building something more advanced and serious 😉.
If you want to build something on Cellframe, join their development Telegram channel!
Thank you for reading!