import Michelson from '@site/src/components/MichelsonDoc/Michelson'; import MichelsonArg from '@site/src/components/MichelsonDoc/MichelsonArg'; import CodeTabs from '@site/src/components/CodeTabs';
Overview โ
INFO
Version Alpha 0.2 A game platform contract (see below) has been originated on Hangzhounet: KT1QW2haDVNiSaTW7NmL8ece16NwBGGpVLZh. The ledger: KT19FUt5vfAGKAiG1rtibTzYnz5yDZxmhfum.
What are state channels? โ
State channels combine the decentralization and security offered by the Tezos blockchain with the throughput and low latency offered by off-chain operations. As such, they provide a "layer two solution" that overcomes scalability limits and reduces operational costs.
By way of analogy, an ordinary legal contract does not require a judge to be present at every interaction of the involved parties. Indeed this is only needed in the comparatively rare cases of disagreement or foul play. The same is true for state channels: they provide a way for parties to interact off-chain and only need to fall back to on-chain operations to settle conflicts.
Games! โ
To explain how state channels work, this guide describes a game platform. It allows users to play games such as chess or tic-tac-toe. A prize for the winner is agreed upon at the start and settled at the end of a game. Actually, the provided framework is slightly more general and it is easy to see how games generalize to other types of contracts, e.g. financial ones.
How does it work? โ
The game platform, represented on-chain by a contract, allows participants to open channels between each other. To assure each other that debt resulting from game outcomes will be settled, they then push bonds that can only be withdrawn under certain conditions. The next step is to actually play the game: the players send each other signed off-chain operations, without any chain interactions. In case of disagreement either player can move the game to the blockchain. This ensures that the players can force each other to respect the rules of the game. If all goes well, very few operations take place on-chain, making game play cheaper (off-chain operations have no associated gas cost) and possibly faster.
The rules of a game are stipulated in a so-called model. (using SmartPy or any other methods to generate Michelson). Each instance of a model is called a game. In each game two players take turns in making moves.
Contracts and examples โ
The contracts for the platform, as well as the game models, can be found under smartpy.io/ide > Templates > Regular Templates > State Channels. In particular, there is:
The main platform contract: management of state channels, games and bonds.
The token ledger: management of FA tokens
A model tester: test a single model before deploying it.
A set of example models, together with scenarios and tests. Each model contains a scenario for the model tester.
A realistic scenario between two players using the testnet platform