Git Product home page Git Product logo

balances-state-channel-example's Introduction

PoC: State channel for payments

Summary

This repository contains a proof of concept of a state channel setup for offchain transfers between two peers. It could be adapted to allow external deposits from generic ERC20 tokens (approve + transferFrom) and ERC777 (direct transfer with hooks). Notice that this is just a proof of concept simplified for showcase. It is missing a lot of features for the sake of simplicity, a few of them would be:

  • Timestamping the signatures so that they can't be used after a certain time has passed.
  • Replay attack protection to avoid use in similar contracts or contracts in other chains.
  • Generalization of channels (ie multiple parallel channels)
  • Challenge periods for withdrawals.

What are state channels

You can check what state channels are here: https://docs.statechannels.org/ . They also offer generalized state channel contracts, but this version is tailored for the use case depicted in the summary.

TL;DR: State channels use Eliptic Curve signatures for offchain transactions with a nonce. All users involved endorse channel changes. The final state of the channel is then comitted on chain by any user, reflecting the final result of all the offchain transactions by checking the validity of the last state. A rogue state cannot be comitted since some rules are enforced via smart contract (eg valid signatures from the users in the channel, nonces that must be incremental, and other rules that you might add).

How is this repository structured

In the Ethereum folder you will find a Truffle project with all the used smart contract code and tests. This should not require an explanation if you have delved as far with general blockchain development on Ethereum as to get interested in state channels (I hope!)

In the CLI folder you will find a (hopefully simple enough) node application that takes a couple of committed JSON keys that you can use to test transfers between two users. As signatures must be committed and shared offchain, a real world scenario would imply some sort of communication between the users. In this case it is JSON file acting as a database. More information can be found in the README.md located in the folder.

balances-state-channel-example's People

Watchers

Mad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.