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.
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
- Install Docker and Docker Compose (Window 10, macOS, Linux)
- Install git
- Place yourself in the repository containing this file
- Clone this repository with vendors using git
git clone --recurse-submodules https://github.com/Magicking/protochannel
- Build the containers using docker-compose
docker-compose build
- Setup environment variables in docker-compose.yml, see below
- Run the prototype
docker-compose up
- Launch your browser and unlock your account in your favorite wallet software Tested with:
- Metamask
- Access interface at:
The API server log shows when event are fired by the smart contract The browser console log contains various debug informations
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
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
- Martin Koeppelmann (Oct. 2015, blog) - How offchain trading will work
- Robert Mccone (Oct. 2015, blog) - Ethereum Lightning Network and Beyond
- Jeff Coleman (Nov. 2015, blog) - State Channels (see also: discussion on /r/ethereum)
- Heiko Hees (Dec. 2015, talk) - Raiden: Scaling Out With Offchain State Networks
- Jeff Coleman (Dec. 2015, interview) - Epicenter Bitcoin: State Networks
- Jehan Tremback (Dec. 2015, blog) - Universal Payment Channels
- Martin Koeppelmann (Jan. 2016, slides) - Scalability via State Channels
- Vitalik Buterin (Jun. 2016, paper) - Ethereum: Platform Review (page 30)
- Dennis Peterson (July 2016, code) - Sparky: A Lightning Network in Two Pages of Solidity
- Ameen Soleimani (Sept. 2016, talk) - An Introduction to State Channels in Depth
- Jeff Coleman (ongoing, wiki) - State Channels Wiki
- Dennis Peterson (Oct. 2016, code) - Gamble Channels: Fast Verifiable Off-Chain Gambling
- Jeff Coleman (ongoing, code) - Toy State Channels
- Heiko Hees (ongoing, code) - Raiden Network
- Sergey Ukustov (ongoing, code) - Machinomy