Adding Funds to a Payment Channel | XRPL Development in JavaScript - Level 4
In this chapter, we will introduce how to add funds (deposit) to an existing payment channel.
Creating the Script
Create a new file named fundPaymentChannel.js in your project directory.
Paste the following code into fundPaymentChannel.js.
Running the Script
Run the script by executing the following command in your command line:
If successful, the console will display the following:
Extending the Expiration Date
You can extend the expiration date while adding funds.
To extend the expiration date, add the Expiration field as shown below when submitting the transaction.
The Expiration field must specify a date later than the current date plus SettleDelay.
Note: The expiration date is different from the CancelAfter option, which cannot be changed.
Checking the Channel’s State
To verify that the funds have been added, check the channel’s state again.
Use the previously created checkChannelBalance.js.
Running the Script
Run the script by executing the following command in your command line:
If successful, the console will display the following:
You can confirm that the Amount has increased to 15000000 drops (15 XRP).
Summary
In this chapter, we explained how to add funds to a payment channel.
Using the PaymentChannelFund transaction, you can make additional deposits to the channel.
You can refer to this sample code to generate a transaction, for example, when clicking a “Deposit” button.
Additionally, you can extend the validity period of the channel, allowing for more transactions.
In the next chapter, we will introduce how to close a payment channel. By going through the closing process, you can reclaim unused funds and finalize the channel’s remaining balance.