๐Ÿ’ฐ
Minimum Viable Payment Channel
Make micro payments in ETH with signatures over a open session

Branch Info

Author: Viraz Malhotra Source code: https://github.com/scaffold-eth/scaffold-eth-examples/tree/payment-channel Intended audience: Intermediate Topics: Scaffold-eth basics, State Channels

๐Ÿƒโ€โ™€๏ธ Quick Start

Table of Contents
  1. 1.
    โ€‹About The Projectโ€‹
  2. 2.
    โ€‹Getting Startedโ€‹
  3. 4.
    โ€‹Practiceโ€‹
  4. 5.
    โ€‹Contactโ€‹

About The Project

We will show you how a Minimal Viable Payment Channel can be built and also will demonstrate how you can spin it up locally as a playground. We take the case of a student and teacher/mentor just to simpilify things, so basically if a student is facing a issue related to code so he can consult a teacher for a time period and create a payment channel and steam eth in the form of micro payments throught the session by just sending in signatures and the teacher can at any time within the session withdraw and close it.

Speed Run

โ€‹โ€‹
โ€‹
โ€‹

Getting Started

Installation

Let's start our environment for tinkering and exploring how NFT auction would work.
  1. 1.
    Clone the repo first
1
git clone -b payment-channel https://github.com/scaffold-eth/scaffold-eth-examples.git payment-channel
2
cd payment-channel
Copied!
  1. 1.
    Install dependencies
1
yarn install
Copied!
  1. 1.
    Start local chain
1
yarn chain
Copied!
  1. 1.
    Start your React frontend
1
yarn start
Copied!
  1. 1.
    Deploy your smart contracts to a local blockchain
1
yarn deploy
Copied!
  1. 1.
    Start the backend server which is responsible for storing signatures
1
yarn backend
Copied!

Smart contracts

Let's navigate to packages/hardhat/contracts folder and check out what contracts we have there.
We are mostly interested in MVPC.sol smart contract which contains all the logic for NFT auction.

MVPC.sol

So basically there are 3 main functions:
  • function open(address signer, address payable destination, uint256 timeout) public payable responsible for opening the channel and setting a session/channel id by encoding the parameters passed in this function
  • function close(bytes32 id, uint256 value, bytes memory signature, bytes memory receiverSignature) public responsible for closing the stream to be calld by the receiver of the stream
  • function withdraw(bytes32 optionalId) public responsible for getting the left over stake back to the channel creator incase the receiver does not close the stream

Practice

Firstly, let's get us some funds using local faucet.
โ€‹โ€‹
โ€‹
โ€‹
open a payment channel and you can also see the previous payment channels created
โ€‹โ€‹
โ€‹
โ€‹
after clicking on channel detail button set the eth stream / minute amount
โ€‹โ€‹
โ€‹
โ€‹
the receiver in this case a teacher can view the payment channel details and can claim and close it any time till the session does not expire
โ€‹โ€‹
โ€‹
โ€‹
the channel creator can close and withdraw the stream funds too espcially when the receiver does not close the channel

Contact

Join the telegram support chat ๐Ÿ’ฌ to ask questions and find others building with ๐Ÿ— scaffold-eth!