Home

Awesome

This repository has been archived on 27.02.2023

The reason for the retirement is that the code is outdated. For a up to date state channel demo please refer to https://github.com/aeternity/state-channel-demo

Step by step tutorial for the coin-toss game

Installation:

  1. To use the Coin Toss State Channel Demo, you need to perform the following steps before cloning this repo and working with it: a. Run an aeternity node

The above json has public keys indicating the accounts as well as their balance in aettos.

b. You need to install and run the AE Channel Service. The AE Channel Service will serve as an automated counterpart that will play the Coin Toss Game against you. Follow this link to install and run the ae-channel-service. Mac Users: For the first build, you might increase the RAM allocated to your docker in the docker desktop menu to at least 2,5 GB of free memory(Here is a screeenshot of the docker properties). For the first time, the ae-channel-service may take a little longer to build. Depending on your machine capacity and your background processes, sometime it may take upto 6-8 hours but patience is the key. Once you start running this, it would become faster eventually.

c. You can run the test on various environments: mainnet, testnet or locally as an independent node mining on its own. You must configure your ae-channel-service properly so it can sign your transactions for you. Sadly, the demo client does not do that so you must fill your key pair here. If you’re running a local standalone test, you must configure your accounts_test.json accordingly.

  1. Clone this repo and run:
$ npm install -g @angular/cli

$ npm install

$ ng serve

then open http://localhost:4200/

Note: The current state of the demo depicts only the "happy path". In case of errors, restart the Node and Channel service (here eventualls delete the data folder) and reload the site.

The application automatically points to your Aeternity Node and AE Channel service at localhost. If you're running them on another host, you can change the according values at src/environments/environment.ts

In case of questions, issues and featur requests, please turn to https://forum.aeternity.com/ .

  1. You can run the test on various environments: mainnet, testnet or locally as an independent node mining on its own. For each of the environments, you must configure your ae-channel-service properly so it can sign your transactions for you.

  2. Depending on your setup, you must configure your network_id depending on the environment

  3. For the node config files: Examples of config files can be found in the ae-channel-service repo. There are two different setups: the difference between them is simply if the node mines with a normal speed or much faster (the config files are linked in 1a). Please note that if you want iris enabled, you shall add a corresponding line in the hard_forks section.

About the game:

Short description, steps marked with (*) require co-signing, that is; signature by both participants

1. channels is opened (*)
2. backend provides contract (*)
3. player provides a stake N tokens and a hash `compute_hash` based on guess which is heads|tails, and the secret key (salt) (*)
4. backend makes a coin_side guess with `casino_pick` and also provides N tokens to be able to participate (*)
5. client reveals `reveal` by prividing key (salt) and the selected coin_side, tokens are now redistributed (*)
6. goto 3 ( ) or shutdown (*) which return tokens on-chain

Description of the final (!) game by Dimitar (progressing in steps might be smart):

Alice wants to gamble. She opens a website, negotiates some channel opening params (initial amounts for example) 
and gets a QR code to scan with her phone/continues in the browser. Using this QR code she opens a state channel 
with the casino. In the SC context, the casino plays the role of a responder. Its node has a backend that handles 
its logic and keys. The backend authenticates or refuses to authenticate incoming requests.

Alice gets a list of possible games via generic messages. Each game is a smart contract. Alice goes with a simple 
turn based game (discuss the game down). She offers the casino to add this smart contract to the state of their 
channel. The backend approves/rejects it. If approved they proceed playing the game via smart contract executions.

Game example: coin toss - Hash Locked Smart Contract. The backend produces a Sophia string - either head or tails. 
It encodes it and gives the produced hash to the smart contract. All Alice sees is a hash and she has to guess if 
it is a head or tails. If she does not answer until the time runs out - the casino can force progress this on-chain 
and claim their reward. If Alice says head/tails - it is the casino's turn to provide the hash and unlock the mystery. 
If it refuses to do so, after the timer runs out, Alice can force progress it on-chain and claim her reward. If the 
hash is provided, someone gets the reward in a civilized manner.

NOTE: This bounty was sponsored by the AE Crypto Foundation.