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

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


Let's start our environment for tinkering and exploring how NFT auction would work.
  1. 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. 1.
    Install dependencies
yarn install
  1. 1.
    Start local chain
yarn chain
  1. 1.
    Start your React frontend
yarn start
  1. 1.
    Deploy your smart contracts to a local blockchain
yarn deploy
  1. 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.


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


Firstly, let's get us some funds using local faucet.
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
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


Join the telegram support chat 💬 to ask questions and find others building with 🏗 scaffold-eth!