Hive Stream: (Update) Support for writing custom contracts on the Hive blockchain

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@beggars·
0.000 HBD
Hive Stream: (Update) Support for writing custom contracts on the Hive blockchain
Whilst building dApps on the Hive blockchain, you'll inevitably want to react to specific actions users perform. If you are familiar with Hive Engine (or Steem Engine) then you might be familiar with how it watches for custom JSON operations on the blockchain.

![Screen Shot 20200402 at 11.31.20 pm.png](https://files.peakd.com/file/peakd-hive/beggars/aaeb5BWR-Screen20Shot202020-04-0220at2011.31.2020pm.png)

After trying to set up and run my own node, I realised that that the Hive Engine node software is limited in that you can't do anything with balances or create anything complicated. I already had my Hive Stream library, so I set out to create a rudimentary contracts system within Hive Stream.

One of my favourite things about the way Hive Engine's smart node software works is the ability to write "smart contracts" using Javascript. Basically, the ability to define "actions" which are matched to an action value inside of a custom JSON payload. I wanted to replicate that same approach, but make it even easier (no Base64 encoding required).

At its core, it's basically just watching for custom JSON operations with a specific property inside of the JSON object on the chain called `hiveContract`. An example contract can be seen [here](https://github.com/Vheissu/hive-stream/blob/master/src/contracts/dice.contract.ts) for an imaginary dice game use Hive Stream. And in this runnable test file [here](https://github.com/Vheissu/hive-stream/blob/master/src/test.ts) you can see how contracts are registered. Consult the [README](https://github.com/Vheissu/hive-stream/blob/master/README.md) for details on how to use the library.

I guess you could describe it as more of a reactive blockchain library, looking for specific properties and matching those to actions. It takes a lot of the work out of needing to write this stuff manually yourself. Why reinvent the wheel? Furthermore, the library now has failover support, if an API node goes down, it'll try one of the other specific API nodes until it works or completely fails. It supports custom JSON operations as well as transfers with custom JSON in the memo which allows you to react to transfers (dice games, deposits, etc).

In the coming weeks, a more standardised approach to using this library to build decentralised applications on the Hive blockchain is coming, but for now, it should do most of the things dApp authors would want to do. I have yet to completely test all of this extensively (however, it is well tested from a unit test perspective), so exercise caution when using this library and feel free to provide feedback and contributions on the repository. I will have a tutorial coming shortly showing you how to create a dice game using this library.
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,