Skip to content

Protochannel is a TicTacToe game using of Ethereum State Channel to do off-chain transactions

Notifications You must be signed in to change notification settings

Magicking/protochannel

Repository files navigation

Protochannel

Protochannel is a prototype project to demonstrate the usage of Ethereum state channel to do off-chain transactions settleabe at any point in time forward manner.

It's a work in progress TicTacToe implementation.

How it works

Player interacts through the Golang API services by pushing signed message (personalSign) with MetaMask. They exchange signed message with state composed of memory, nonce, counter, state function transition.

State:

Offset Byte length Description
0 1 Opcode for the state transition function: NOP(0), PUT(x,y)(1)
1 1 Operation counter: nonce
2 1 Parameter 1
3 1 Parameter 2
4 9 Tic Tac Toe Board game memory

State transition is enforced by games rules in Solidity Smart Contract

TODO:

  • Specifications
  • Messaging
  • Settlement
  • Smart contract
  • Documentation
  • docs/protochannel.yml
  • Tests
  • Use libp2p

How to run the prototype ?

  1. Install Docker and Docker Compose (Window 10, macOS, Linux)
  2. Install git
  3. Place yourself in the repository containing this file
  4. Clone this repository with vendors using git git clone --recurse-submodules https://github.com/Magicking/protochannel
  5. Build the containers using docker-compose docker-compose build
  6. Setup environment variables in docker-compose.yml, see below
  7. Run the prototype docker-compose up
  8. Launch your browser and unlock your account in your favorite wallet software Tested with:
  • Metamask
  1. Access interface at:

The API server log shows when event are fired by the smart contract The browser console log contains various debug informations

Environment variables

WS_URI is the url of a capable WebSocket RPC node, if private blockchain, the node networkid must match genesis chainid for Metamask to work correctly

  • WS_URI=ws://1.1.3.7:8546

DB_DSN is the DSN of a PostgreSQL database (embedded with docker-compose)

  • DB_DSN=host=postgres user=f3b1be969686afb4520ce dbname=protochannel sslmode=disable password=839169c0ea5e59146a

PRIVATE_KEY is a private key in hex format, used if needed to emit transaction to or deploy smart contract

  • PRIVATE_KEY=8e973e8e3d06a321d7285695560a45bd4946eb6f59410732b048c59a0174cc09 # 0xcd5bb3a1E6d7676DAD570566A455dC38b7e3EaDf

CONTRACT_ADDRESS is the contract address of the deployed contract that the service should interact with, empty will trigger a new deployment

  • CONTRACT_ADDRESS=

RETRY is the number of retry the service will perfom before giving up

  • RETRY=3

FAQ

How to generate API server ?

swagger generate server -f docs/protochannel.yml

See: Go Swagger

How to generate API Smart Contract ABI ?


abigen -sol contracts/tictactoe.sol --pkg internal -out internal/tictactoe.go

See: Abigen

How to install Docker and Docker Compose? See: Docker Installation See: Docker Compose Installation

How to install Git ? See: Installing Git

Resources

Source: https://www.reddit.com/r/ethereum/comments/6fde8t/ethereum_payment_channels_in_50_lines_of_solidity/dihe3tj/

About

Protochannel is a TicTacToe game using of Ethereum State Channel to do off-chain transactions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages