Putting It All Together

We started with an idea, then some sample code, and now we have a fully operational Death Star contract. Now we just need a network to deploy it to, and a way to talk to the contract.

Repo: https://github.com/DerekJarvis/crpg_contract

Ant, meet sledgehammer

As mentioned in Why Kaleido Firefly?, we're using this stack because it gives us everything we need to set up our own blockchain and easily expose contracts through a Web API. It actually gives us a lot more than that and it doesn't get in our way (much). This means we have room to grow.

The Kaleido Firefly Docs are very good, and so are the open source Firefly docs. I won't repeat much of their content here. I will use the terms "Firefly" and "Kaleido Firefly" interchangeably because I want to give credit to the company that first developed this software.

Following their Getting Started guide will set up a local Firefly node on your machine. Make sure you use the "fabric" option for the blockchain.

From there, you need to deploy your own contract. There's also a nice guide for deploying Fabric contracts on Firefly.

How this project works

Docker Compose Override

This is a side-note which will hopefully get removed later. The current implementation of Firefly doesn't allow the FFI interface file to define detailed parameters for functions. It seems to just pass them all as strings and rely on the consumer (in our case, the Fabric Go SDK) to coerce them into the correct type. I've done a write-up of why I think this isn't ideal, and made a pull request to improve the implementation.

Chain Types

This directory contains objects (and their interfaces, helpers, etc) that are written to chain. 


This directory contains the contract itself, and some helpers, which will use the Chain Types to read and write from the chain.

Helper Scripts

The README gives some detail about what these scripts do. To summarize again:

  • 0_init.sh
    • Ensure the Fabric binaries are present
    • Ensure the Firefly binaries are present
    • Ensure the patched Fabconnect docker image is present
    • Restart or Create a development network using Firefly
    • Update the development network to use the patched Fabconnect docker image
  • 1_reset.sh
    • Clean up any previously compiled contract
    • Reset & Restart the dev Firefly stack
    • Package the chaincode
    • Deploy the chaincode
  • 4_test.sh
    • Define the contract interface with Firefly
    • Expose the contract through WebAPIs with Firefly
    • Use the WebAPIs to:
      • Create players
      • Create a character
      • Buy Packs
      • Open Packs
      • Create a dungeon
      • List the dungeon
      • Start a dungeon match
      • Score a dungeon match

Misc Files


This is the interface definition file that tells Firefly what functions our contract has, the arguments they accept, and their return values. For simplicity, we call this json file from a test to register it with the local Firefly node. This makes it much easier to tweak the definition and automatically test things again.

In the future, it'd be pretty neat to make something that will generate this FFI file by using reflection on the contract.

Taking a look

If you open the links mentioned in the README, you can see the activity on your locally deployed nodes.

Go forth and tinker

This is the end of our initial exploration. I hope these posts have been helpful, and that the code gives a good idea of one possible approach to structuring a contract. 

From here, we just need to do the thing...