Claiming Funds from a Payment Channel | XRPL Development in JavaScript - Level 4
In this chapter, we will introduce how to claim funds from the balance of a created payment channel.
Prerequisites
Bob has already performed the following actions for Alice:
- Created a channel and deposited
10 XRP
. - Completed a total of
1 XRP
worth of off-ledger transactions.
Creating the Script
-
Create a new file named
claimPaymentChannel.js
in your project directory. -
Paste the following code into
claimPaymentChannel.js
.This code is a sample for claiming transactions for a specified channel ID, payment amount, and signature.
Running the Script
-
Run the script by executing the following command in your command line:
-
If successful, the console will display the following:
Alice has successfully claimed the specified channel ID.
-
Attempting to claim the same amount again will naturally fail.
Summary
If the balances are as follows, the process has been successful.
- Alice: 100.999988 XRP
- Bob: 89.999988 XRP
Check Alice and Bob’s addresses using the explorer for the testnet.
- Alice claimed
1 XRP
from the payment channel created by Bob, but since she bore the transaction fee, she actually received0.999988 XRP
. - Bob initially deposited
10 XRP
with the PaymentChannelCreate transaction, paying the deposit and fees upfront, so his balance should be89.999988 XRP
.
Additionally, it is beneficial to examine the transaction data for more detailed insights.