We launched an example state channel app!
Back in June, we published a description of ForceMove — our simple but powerful state channel framework. The aim was to start with the simplest possible framework that was general enough for a wide variety of use cases. This approach has paid off, enabling us to launch the first ForceMove app at Devcon IV.
Today we want to share our app with you — a Rock Paper Scissors game, live on Ropsten! As part of the game, we’ve given you four bots against which to pit your wits (or just your luck?). So far no-one has discovered the cheat to beat the psychic bot, so if you’re up for a challenge, give it a go!
The app is fully open-source on github and licensed under the MIT license. We wanted to make it possible for developers to dive right into the code and learn about the patterns used to build state channel applications. We hope that the code will serve as a useful starting point for anyone wanting to build a state channel game.
Hold up, what’s a state channel anyway?
You’re probably aware of projects like Raiden and Connext, which are building payment channels — ways of exchanging payments by exchanging signed agreements off-chain. State channels are more general than payment channels allowing for interactions that more complex than transferring value. State channels are to payment channels as Ethereum is to Bitcoin. In a state channel, the signed agreements contain not just balances but also a shared state. The state could describe the pieces on a chess board or the intermediate steps of a computation.
You’re probably already thinking of a few awesome uses for state channels. Using state channels today is possible but, unfortunately, is not straight-forward. The rules of the application or game have to be carefully enforced on-chain and off-chain. You need to define how a channel is closed so that a smart contract pays each participant the amount to which they are entitled. What about disputes, challenges, users losing internet connection, malicious attacks?
ForceMove and StateStash
The ForceMove framework does the hard work of handling opening and closing of the state channel, as well as taking challenges on-chain when communication between players breaks down. To develop an app on top of ForceMove, all that is required is to develop a smart contract that defines the valid states of the app as well as the valid transitions between those states. You can reference the Rock-Paper-Scissors app to see that these states and transitions can be quite simple.
Our app also includes “StateStash” — a prototype channel wallet, responsible for storing the exchanged states and managing the deposit, withdrawal and any on-chain challenges/responses. A channel wallet is vital for any state channel application because the signed messages that a user receives from others are as good as ETH. These messages need to be safely stored. Furthermore, in some applications, the user might be required to validate and sign transactions at very high speed (e..g >10 per second in a real-time game). Doing this in a wallet like MetaMask is clearly infeasible, so StateStash can be setup to auto-sign transactions, provided that the rules of the channel and some pre-specified conditions are met.
The framework implements the entire challenge-response workflow for dealing with off-chain communication breakdowns. An on-chain challenge can be used to conclude the channel. Alternatively, if the player being challenged responds (i.e. you have forced them to move), the game can be brought back off-chain and continued. You can see challenges in action in the Rock Paper Scissors app.
Get in touch!
Follow us on Twitter for more posts on the making of Rock Paper Scissors and other state channel topics.
Finally, many thanks to Andrew Hunt, Neil Whitehead, Andrew Stewart, Alex Gap and Mike Kerzhner for their hard work bringing the project to fruition!