mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-28 23:55:49 +00:00
Migrate code snippets from xrpl.js and xrpl-py
This commit is contained in:
@@ -12,13 +12,11 @@ import {
|
||||
|
||||
const client = new Client('wss://s.altnet.rippletest.net:51233')
|
||||
|
||||
void claimPayChannel()
|
||||
|
||||
// The snippet walks us through creating and claiming a Payment Channel.
|
||||
async function claimPayChannel(): Promise<void> {
|
||||
await client.connect()
|
||||
|
||||
// creating wallets as prerequisite
|
||||
// Creating wallets as prerequisite
|
||||
const { wallet: wallet1 } = await client.fundWallet()
|
||||
const { wallet: wallet2 } = await client.fundWallet()
|
||||
|
||||
@@ -26,13 +24,13 @@ async function claimPayChannel(): Promise<void> {
|
||||
console.log(`Balance of ${wallet1.address} is ${await client.getXrpBalance(wallet1.address)} XRP`)
|
||||
console.log(`Balance of ${wallet2.address} is ${await client.getXrpBalance(wallet2.address)} XRP`)
|
||||
|
||||
// create a Payment Channel and submit and wait for tx to be validated
|
||||
// Create a Payment Channel and submit and wait for tx to be validated
|
||||
const paymentChannelCreate: PaymentChannelCreate = {
|
||||
TransactionType: 'PaymentChannelCreate',
|
||||
Account: wallet1.classicAddress,
|
||||
Amount: '100',
|
||||
Amount: '100', // 10 XRP
|
||||
Destination: wallet2.classicAddress,
|
||||
SettleDelay: 86400,
|
||||
SettleDelay: 86400, // 1 day in seconds
|
||||
PublicKey: wallet1.publicKey,
|
||||
}
|
||||
|
||||
@@ -44,7 +42,7 @@ async function claimPayChannel(): Promise<void> {
|
||||
console.log("PaymentChannelCreate transaction response:")
|
||||
console.log(paymentChannelResponse)
|
||||
|
||||
// check that the object was actually created
|
||||
// Check that the object was actually created
|
||||
const accountObjectsRequest: AccountObjectsRequest = {
|
||||
command: 'account_objects',
|
||||
account: wallet1.classicAddress,
|
||||
@@ -52,23 +50,21 @@ async function claimPayChannel(): Promise<void> {
|
||||
|
||||
const accountObjects = (await client.request(accountObjectsRequest)).result
|
||||
.account_objects
|
||||
|
||||
console.log("Account Objects:", accountObjects)
|
||||
|
||||
// destination claims the Payment Channel and we see the balances to verify.
|
||||
// Destination claims the Payment Channel and we see the balances to verify.
|
||||
const paymentChannelClaim: PaymentChannelClaim = {
|
||||
Account: wallet2.classicAddress,
|
||||
TransactionType: 'PaymentChannelClaim',
|
||||
Channel: hashes.hashPaymentChannel(
|
||||
wallet1.classicAddress,
|
||||
wallet2.classicAddress,
|
||||
paymentChannelResponse.result.Sequence ?? 0,
|
||||
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||
),
|
||||
Amount: '100',
|
||||
}
|
||||
|
||||
console.log("Submitting a PaymentChannelClaim transaction...")
|
||||
|
||||
const channelClaimResponse = await client.submit(paymentChannelClaim, {
|
||||
wallet: wallet1,
|
||||
})
|
||||
@@ -81,3 +77,5 @@ async function claimPayChannel(): Promise<void> {
|
||||
|
||||
await client.disconnect()
|
||||
}
|
||||
|
||||
void claimPayChannel()
|
||||
|
||||
Reference in New Issue
Block a user