Signing and Verifying Off-Ledger Payments | XRPL Development in JavaScript - Level 4
In this guide, we will introduce how to sign and verify off-ledger payments.
Creating the Script
-
Create a new file named
signPaymentChannelClaim.js
in your project directory. -
Paste the following code into signPaymentChannelClaim.js.
This code is a sample that performs 1,000 payments.
- In the following loop, the payment amount increases by 0.001 each time, resulting in a total payment of up to 1 XRP.
Running the Script
-
Run the script by executing the following command in your command line:
-
If successful, the console will display the following results, so check the string displayed to the right of
Generated signature:
and make a note of it.It took only
1.605s
to process 1,000 off-ledger payments (results from the author’s local environment).This demonstrates how off-ledger transactions can handle over 1,000 payments in just a few seconds.
The
signature
value obtained in the result above,7465B7BCC66F1053D4CB8EF3785BE951A235868420F546160EF446429DA58632EEBBA90810F6714500E7B0A73E9DBABFE47307DC6BEC9D911D24DB473988BE04
, will be needed in the next chapter, so make a note of it.
Checking the Channel State
Let’s check the state of the channel at this point.
Creating the Script
-
Create a new file named
checkChannelBalance.js
in your project directory. -
Paste the following code into checkChannelBalance.js.
To check the state of the channel, use the account_channels command.
Running the Script
-
Run the script by executing the following command in your command line:
-
If successful, the console will display the following:
Summary
In this chapter, we explained how to sign and verify off-ledger payments and how to check the state of the payment channel.
Off-ledger payments enable rapid and efficient execution of multiple payments by verifying the validity through signatures. Additionally, checking the state of the payment channel allows you to understand the current balance and the total amount deposited in the channel.
In the next chapter, we will introduce how to claim the funds. Learn the steps to claim the channel’s balance using the obtained signature.