transcript

XRP DEV - Using PaymentChannels (70.000 TPS) on the XRP Ledger

Thumbnail of the video “XRP DEV - Using PaymentChannels (70.000 TPS) on the XRP Ledger”
Download Markdown
Community upload. AI output has not been independently verified.

Hello and welcome to another video. In this video we will talk a little bit more about payment channels, and we'll show you a code example. I've been playing around with it a little bit. It's a little bit harder to do, but I think it was worth it. I spent lots of hours trying to set all of it up. The idea is basically that we can do normal payments. We already know that we can do normal on-ledger payments, and they are validated and afterwards persisted, meaning that the settlement happens immediately. I will quickly show it in the live feed here, so you can see that when you do a transaction, for example if you send XRP from your address to another one, it is validated immediately and settled immediately as well. But there's also another way to handle larger volume. Currently this can handle up to 1,500 transactions per second, and they are also trying to increase the on-chain performance. There is also the possibility of creating payment channels, and the general idea is that you first go to the site. The first on-chain transaction is the payment channel fund transaction. I'm just looking to see if there's a nicer graph here, but no, it doesn't look nice. Okay, I'm going to draw it myself.

I'm going to oversimplify all of that to break it down a little bit, but the general idea is that we first do a payment channel fund transaction. This means that the person who wants to pay, let's say a person who wants to pay a lot in smaller amounts and very frequently, can create a payment channel to person B. Let's say here we have the payer, the person who wants to pay, and the second one is the receiver. The first thing the payer does is create a payment channel fund transaction. The payer says how much he is willing to lock up to create the channel. For example, you can create a payment channel fund with 10 XRP, meaning that this channel can consume at most 10 XRP. Then at some point the receiver can do a payment channel claim transaction, and as soon as the receiver does that, he consumes the amount he was promised. That part is all happening on-chain. Now they can communicate over any communication channel they want and handle the claims. The payer, for example, wants to pay one extra XRP, so the payer sends his signature for one extra XRP to the receiver, and the receiver can store that. It is cumulative.

Let's go a little deeper into that. The payer sends a signature. For the sake of making it look cooler, I'm just going to copy a signature here. The payer sends this signature to the receiver. The signature contains the command or transaction: yes, I'm going to pay you one XRP. The receiver gets it and can store it, and they can do lots of microtransactions super fast. They already tested this in 2011, and they could handle around 70,000 transactions per second. That's because it's based only on how fast the payer's hardware can sign the transaction, and I think they did a test in 2011 where they were able to do 70,000 transactions per second. That's how these payment channels work. You can do lots and lots of microtransactions, one drop, two drops, whatever. That's basically what Coil is doing with Web Monetization. The signature then gets sent to the receiver, like I said. For the first one, the payer says he's going to pay one XRP. Afterwards you can do another transaction, and a new signature gets created, which for example says he is going to pay two XRP or three XRP, and that signature is sent again. It is always incremental. The receiver can verify each one whenever it is received, but I'm not going to look that closely at that. That's the general idea. As soon as the receiver says he is done and wants his money, he can submit a payment channel claim transaction with the latest signature from the payer, and then it gets resolved, and the receiver gets the money he was promised. That's how it all works. I hope I explained it clearly, but now we'll do it hands on.

For all of that we have two accounts here. It's super simple. I'm also going to quickly add a tag here. Let's say that's the payer. Then the other one is the receiver. Okay, so here we have the payer and here we have the receiver. The idea is that the payer creates a payment channel with 10 XRP to the receiver. Then the payer will send a signature to the receiver, like I said, and then the receiver can make the claim. Let's start with the simple part. We will create a payment channel for 10 XRP. Let's also have a quick look at the code. It's very simple. Here's the payment channel create function. We will create a payment channel with 10 million drops, so 10 XRP. It goes to the receiver's address, it should settle after 10 minutes, and that's the payer's public key. I tried to put it into a simple overlay so it's easier. I'm going to click on that, and now the payer has created his own payment channel.

Now the next part: the payer can create a signature. He pastes in the channel ID, and his secret is incorporated there. Now we can say, for example, I want to pay one XRP. I will authorize the payee to get one XRP, and there's his signature. He sends that first signature to the receiver, and it is automatically verified. They always have to do the code, and then you can say, for example, I will give you another one. He increments it to two, and again he gets the signature and sends it to the payee. Let's say this has increased to five XRP, and some other number of drops. It doesn't really matter, but let's take some numbers here: five XRP and 432,405 drops. I'm going to send it again, and now there is the signature. This signature has to be delivered to the receiver. I'm doing it on the same computer, which is why it doesn't matter. The receiver now has a payment channel claim transaction, and we will paste the signature in here and the channel ID in here. We have to copy the channel ID as well, and we need to specify the total amount. We'll paste the number there and we're good to go. I'm saving again, and now I'll go into my simple React application. There it is. Now the receiver will make his claim. I'm going to click on make claim, and we're done. I'll also have a quick look at the toolkit, and you can see here that the payment channel claim was made. I just received my five-point-something XRP. I made a claim for 5.43 XRP, and it has already been added to my balance, so it was settled on-chain. The payment channel should now be closed, and the other channel should hopefully also give us the rest of the balance back.

That's how payment channels work. I oversimplified it, because the much more difficult part is the communication: the payer gives the signature to the receiver, the receiver has to verify the claim, and then he can allow whatever it unlocks. This repeats many times. That's the general idea, and I wanted to show you the feature. These payments are not happening on-chain. That's why they are not limited by the transactions per second of the ledger. They are settled afterwards. This feature is already battlefield tested. I could look up how old it is, but I was able to do it myself, and it was very cool, and also exhausting. That's it basically. Thanks for watching, and see you in the next video.