Skip to content

Latest commit

 

History

History
112 lines (69 loc) · 4.7 KB

minimum-viable-payment-channel.md

File metadata and controls

112 lines (69 loc) · 4.7 KB
description
Make micro payments in ETH with signatures over a open session

💰 Minimum Viable Payment Channel

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. About The Project
  2. Getting Started
  3. Exploring smart contracts
  4. Practice
  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

ethdenvervideo

Getting Started

Installation

Let's start our environment for tinkering and exploring how NFT auction would work.

  1. Clone the repo first
git clone -b payment-channel https://github.com/scaffold-eth/scaffold-eth-examples.git payment-channel
cd payment-channel
  1. Install dependencies
yarn install
  1. Start local chain
yarn chain
  1. Start your React frontend
yarn start
  1. Deploy your smart contracts to a local blockchain
yarn deploy
  1. Start the backend server which is responsible for storing signatures
yarn backend

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

open a payment channel and you can also see the previous payment channels created

per min

after clicking on channel detail button set the eth stream / minute amount

teacher

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

close

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!