PART 2 : STATE CHANNELS

State and payment channels are among the different off-chain scaling solutions that are looking to make blockchains more efficient and scalable. Plenty of transactions can be done off the main chain, avoiding congestion, decreasing the transaction cost, and increasing the transaction speed. This research delves into state and payment channels, implementations, and applications.


STATE CHANNELS

State channels are Layer 2 solutions where participants can run a series of transactions off the main blockchain. Only the final state is recorded on-chain, reducing the load on the blockchain network.

THEORETICAL STEPS

Planning Stage:

  • Players lock a quantity of cryptocurrency into a multisig address on the main blockchain.
  • Smart contracts govern the actions over the state channel
  • A multisig (multi-signature) wallet requires multiple private keys to authorize a transaction, enhancing security by reducing the risk of a single point of failure.

Interaction Phase:

  • Users send messages that, when signed, encapsulate a transaction or a change of state.
  • These transactions are not broadcasted to the blockchain but are shared directly among participants.

Settling-in Stage

  • Participants agree to close the channel by sending the final state to the blockchain.
  • The final state is proved and recorded on the blockchain by updating balances accordingly.
PSEUDO CODE

EXAMPLES

Example 1 : “CHESS MATCH”

Suppose you and a friend would like to play chess, but you would rather not pay an Ethereum transaction fee for every move made on the blockchain. Instead, you could open a state channel, creating a private channel between you two where you can play the game off-chain.

Here’s how it goes:

  1. OPEN CHANNEL: You and your friend can have an off-chain state channel, which can also be done without locking any funds if there’s no money involved.
  2. OFF-CHAIN INTERACTION: Off-chain interaction, in this case, refers to playing the game, say, making moves or turns inside the game. Such an interaction is fast and free from fees.
  3. STATE UPDATING: Any new move played by either you or your friend will update the state of the channel(“I moved my bishop to E4”).
  4. CLOSING THE CHAIN: The game’s final state will be first off the chain agreed at the point of the game’s completion.

This way, you can avoid incurring transactional costs and make their gaming experience smooth without any implications for them.


Example 2 : “FANTASY SPORTS BETTING”

Suppose you and your friend are playing a decentralized fantasy sports betting Dapp that runs over Ethereum. Instead of settling every bet on the main chain, which might be slow and expensive due to Ethereum gas prices, the Dapp uses a state channel to facilitate efficient interaction.

Here’s a breakdown of the scenario:

1. Start a Payment Channel:

  • You and your friend both put 20 ETH into a smart contract, which, in the meaning of this game, was supposed to represent its state channel.
  • Your smart contract is your escrow wallet.

2. Off-Chain Interaction:

  • You make a lot of bets on many matches and events throughout the month-long fantasy sports league within the DApp.
  • Each bet will update both your balances and your off-chain outcomes.

3. Update State: Here is an example five dummy bet entries and their outcomes:

Bet #EventYour Bet (ETH)Friend’s Bet (ETH)OutcomeState Update: Your BalanceState Update: Friend’s Balance
1Football Match 153Your team wins+3 (23 total)-3 (17 total)
2Basketball Game 144Your friend’s team wins-4 (19 total)+4 (21 total)
3Tennis Match 125Your team wins+5 (24 total)-5 (16 total)
4Football Match 233DrawNo change (24 total)No change (16 total)
5Basketball Game 262Your team wins+2 (26 total)-2 (14 total)
Ledger Table

4. State Channel Termination:

  • On the last day of the month, we settle the final balances by submitting the final state to the Ethereum blockchain. The smart contract then distributes the funds according to the bet outcomes.
  • The smart contract does all the calculations regarding the money earned according to the wage outcome

Therefore, using a state channel makes it cheap for the user in terms of both time and money, as it avoids an on-chain individual transaction for every single bet.


CONCLUSION

State channels offer a powerful solution for scaling blockchain transactions by allowing multiple interactions to occur off-chain, thereby reducing congestion and transaction costs on the main blockchain. By leveraging multisig wallets and smart contracts, state channels ensure secure and efficient transaction processing. In the planning stage, participants lock funds and set up the necessary smart contracts. During the interaction phase, users exchange signed messages representing transactions directly among themselves. Finally, in the settling stage, the agreed final state is submitted to the blockchain, updating balances accordingly. This approach is exemplified in scenarios such as playing games or betting on sports, where numerous transactions can occur off-chain, only recording the final outcome on-chain. Overall, state channels enhance the scalability and usability of blockchain applications by providing a seamless and cost-effective transaction experience.

Leave a Reply

Your email address will not be published. Required fields are marked *