At Kunstmaan we are hard at work to bring the first Blockchain based solutions into production. We chose Multichain to power our prototype demoed on the KBC Innovation fair in December 2015 and have continued to invest time and resources in getting this project production ready. We needed to interface with Multichain via its JsonRPC API and since there was no PHP library available we created one. It's this library that we release as our final open source contribution for 2015.

Getting a Docker Multichain cluster up and running

Before you can start developing a Multichain based solution you need a three server cluster up and running. Since Vagrant development solutions take up too much resources, we created Docker images. 

The configuration for this cluster is defined by creating the following docker-compose.yml file:

version: '2'

services:
    masternode:
        image: kunstmaan/master-multichain
        ports:
            - "7447:7447"
            - "8000:8000"
        environment:
            VIRTUAL_HOST: mulichain-master.docker
            VIRTUAL_PORT: 8000
    explorer:
        image: kunstmaan/explorer-multichain
        depends_on:
            - masternode
        ports:
            - "2750:2750"
        environment:
            VIRTUAL_HOST: multichain-explorer.docker
            VIRTUAL_PORT: 2750
        links:
            - masternode
    slavenode1:
        image: kunstmaan/node-multichain
        depends_on:
            - masternode
        links:
            - masternode
    slavenode2:
        image: kunstmaan/node-multichain
        depends_on:
            - masternode
        links:
            - masternode

You can then start this cluster by running docker-compose:

sudo docker-compose up

NOTE: these images are only for development use. They allow any node to connect and administer the cluster, and they open up the JsonRPC interface to everyone, everywhere!

UPDATE: We've added the Multichain Explorer image to inspect your blockchain.

Using the PHP Library

Now that we have a cluster up and running, we can start using the PHP library. Install the libray and it's dependencies into your project by running:

composer require kunstmaan/libphp-multichain

You now have the full power of the API at your disposal. A simple example is creating a new address. Ofcourse you need to change the URL...

$client = MultichainClient("http://<chainurl>:8000", 'multichainrpc', '79pgKQusiH3VDVpyzsM6e3kRz6gWNctAwgJvymG3iiuz', 3);
$address = $client->setDebug(true)->getNewAddress();

The "tests" folder contains a whole lot of other examples, be sure to check them out!

If you find any issues or have ideas or pull requests, don't hesitate to open them on Github!

Written by

Roderik van der Veer

Technology Director at Kunstmaan, passionate about innovation and the technology to do so.

Follow @r0derik