Is there a smart contract that shows how to implement payment channels?

Is there an OpenZeppelin library contract that helps in implementing payment channels (I checked github repo. Could not find) or is there a smart contract that shows how channels can be implemented. I can see in the internet that all articles are about the theory of how a payment channel could work. I was wondering if there was an example of the same.

2 Likes

We don’t have anything payment-channel specific at the moment, no. What sort of primitives would you like to see to help you build something of this sort?

2 Likes

Could you please explain more about payment channels.

2 Likes

I am having a situation where the state of a smart contract is being updated frequently by the users. I am now exploring a solution where the state updates since the channel creation is done between the parties of channel where one party will share the signed hash of the updated state as well the change he/she made to the other party. They validate the change off-channel. The other party will do the same to make more updates. Finally when one of them wants to close the channel, they can sent the update they received from the opposite party as well as a state change they want to make to the contract. The contract uses ecrecover to check if the previous state’s hash was signed by the non-sender party as well as checks the validity of the state update the sender is trying to make. I want to know if this is the optimal way. If there is any better alternative?

1 Like

There are many ways to implement this sort of thing, with multiple trade-offs. At a glance, what you describe seems to make sense, but your specific requirements may dictate different solutions.

Regarding signature checking, you’ll probably want to use our ECDSA library.

2 Likes

Thank you. will check out.

1 Like