Skip to content

Commit fb33561

Browse files
committed
Address review comments
1 parent 7f16532 commit fb33561

File tree

6 files changed

+63
-49
lines changed

6 files changed

+63
-49
lines changed

_code-samples/batch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Code samples showing how to create and submit a [Batch transaction](https://xrpl.org/docs/concepts/transactions/batch-transactions).
44

5-
Both for single and multi account batch transactions.
5+
Both for single and multi-account batch transactions.

_code-samples/batch/js/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Code samples showing how to create and submit a [Batch transaction](https://xrpl.org/docs/concepts/transactions/batch-transactions) with Javascript.
44

5-
Both for single and multi account batch transactions.
5+
Both for single and multi-account batch transactions.
66

77
## Single Account Batch Transaction
88

_code-samples/batch/js/multiAccountBatch.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ const client = new xrpl.Client("wss://s.devnet.rippletest.net:51233/")
1313
await client.connect()
1414

1515
// Create and fund wallets
16-
console.log("=== Funding new wallets from faucet... ===")
17-
const { wallet: alice } = await client.fundWallet()
18-
const { wallet: bob } = await client.fundWallet()
19-
const { wallet: charlie } = await client.fundWallet()
20-
const { wallet: thirdPartyWallet } = await client.fundWallet()
16+
console.log("=== Funding new wallets from faucet... ===");
17+
const [
18+
{ wallet: alice },
19+
{ wallet: bob },
20+
{ wallet: charlie },
21+
{ wallet: thirdPartyWallet },
22+
] = await Promise.all([
23+
client.fundWallet(),
24+
client.fundWallet(),
25+
client.fundWallet(),
26+
client.fundWallet(),
27+
]);
2128

2229
console.log(`Alice: ${alice.address}, Balance: ${await client.getXrpBalance(alice.address)} XRP`)
2330
console.log(`Bob: ${bob.address}, Balance: ${await client.getXrpBalance(bob.address)} XRP`)
@@ -26,7 +33,7 @@ console.log(`Third-party wallet: ${thirdPartyWallet.address}, Balance: ${await c
2633

2734
// Create inner transactions --------------------------------------------
2835
// REQUIRED: Inner transactions MUST have the tfInnerBatchTxn flag (0x40000000).
29-
// This marks them as part of a batch (allows Fee: 0 and empty SigningPubKey).
36+
// This marks them as part of a batch (requires Fee: 0 and empty SigningPubKey).
3037

3138
// Transaction 1: Charlie pays Alice
3239
const charliePayment = {
@@ -63,8 +70,8 @@ console.log(JSON.stringify(batchTx, null, 2))
6370
// Validate the transaction structure
6471
xrpl.validate(batchTx)
6572

66-
// Set the expected number of signers for this transaction.
67-
// "autofill" will automatically add Fee: "0" and SigningPubKey: "".
73+
// Set the expected number of signers, which is 2 (Bob and Charlie) in this case, for this transaction.
74+
// "autofill" will automatically add Fee: "0" and SigningPubKey: "" to inner transactions.
6875
const autofilledBatchTx = await client.autofill(batchTx, 2)
6976

7077
// Gather batch signatures --------------------------------
@@ -91,6 +98,7 @@ const submitResponse = await client.submitAndWait(combinedSignedTx,
9198
if (submitResponse.result.meta.TransactionResult !== "tesSUCCESS") {
9299
const resultCode = submitResponse.result.meta.TransactionResult
93100
console.warn(`\nTransaction failed with result code ${resultCode}`)
101+
await client.disconnect()
94102
process.exit(1)
95103
}
96104

@@ -121,6 +129,7 @@ for (let i = 0; i < rawTransactions.length; i++) {
121129
}
122130
if (hasFailure) {
123131
console.error("\n--- Error: One or more inner transactions failed. ---")
132+
await client.disconnect()
124133
process.exit(1)
125134
}
126135

_code-samples/batch/js/singleAccountBatch.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ const client = new xrpl.Client("wss://s.devnet.rippletest.net:51233/")
1414
await client.connect()
1515

1616
// Create and fund wallets
17-
console.log("=== Funding new wallets from faucet... ===")
18-
const { wallet: sender } = await client.fundWallet()
19-
const { wallet: wallet1 } = await client.fundWallet()
20-
const { wallet: wallet2 } = await client.fundWallet()
17+
console.log("=== Funding new wallets from faucet... ===");
18+
const [{ wallet: sender }, { wallet: wallet1 }, { wallet: wallet2 }] =
19+
await Promise.all([
20+
client.fundWallet(),
21+
client.fundWallet(),
22+
client.fundWallet(),
23+
]);
2124

2225
console.log(`Sender: ${sender.address}, Balance: ${await client.getXrpBalance(sender.address)} XRP`)
2326
console.log(`Wallet1: ${wallet1.address}, Balance: ${await client.getXrpBalance(wallet1.address)} XRP`)
2427
console.log(`Wallet2: ${wallet2.address}, Balance: ${await client.getXrpBalance(wallet2.address)} XRP`)
2528

2629
// Create inner transactions --------------------------------------------
2730
// REQUIRED: Inner transactions MUST have the tfInnerBatchTxn flag (0x40000000).
28-
// This marks them as part of a batch (allows Fee: 0 and empty SigningPubKey).
31+
// This marks them as part of a batch (requires Fee: 0 and empty SigningPubKey).
2932

3033
// Transaction 1
3134
const payment1 = {
@@ -66,14 +69,15 @@ xrpl.validate(batchTx)
6669
console.log("\n=== Submitting Batch transaction... ===")
6770
const submitResponse = await client.submitAndWait(batchTx, {
6871
wallet: sender,
69-
// "autofill" will automatically add Fee: "0" and SigningPubKey: "".
72+
// "autofill" will automatically add Fee: "0" and SigningPubKey: "" to inner transactions.
7073
autofill: true
7174
})
7275

7376
// Check Batch transaction result --------------------------------
7477
if (submitResponse.result.meta.TransactionResult !== "tesSUCCESS") {
7578
const resultCode = submitResponse.result.meta.TransactionResult
7679
console.warn(`\nTransaction failed with result code ${resultCode}`)
80+
await client.disconnect()
7781
process.exit(1)
7882
}
7983
console.log("\nBatch transaction submitted successfully!")
@@ -103,6 +107,7 @@ for (let i = 0; i < rawTransactions.length; i++) {
103107
}
104108
if (hasFailure) {
105109
console.error("\n--- Error: One or more inner transactions failed. ---")
110+
await client.disconnect()
106111
process.exit(1)
107112
}
108113

docs/tutorials/how-tos/use-batch-transactions/send-a-multi-account-batch-transaction.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ labels:
99
---
1010
# Send a Multi-Account Batch Transaction
1111

12-
This tutorial shows you how to create a [Batch transaction][] containing transactions from multiple accounts, where each account must sign the Batch transaction. Any account, even one not involved in the inner transactions, can submit the batch.
12+
This tutorial shows you how to create a [Batch transaction][] containing transactions from multiple accounts, where each account must sign the `Batch` transaction. Any account, even one not involved in the inner transactions, can submit the batch.
1313

1414
## Goals
1515

1616
By the end of this tutorial, you will be able to:
1717

18-
- Create a Batch transaction with multiple inner transactions, signed by multiple accounts, and submitted by a third party account.
19-
- Configure the Batch transaction to ensure atomicity, so that either all inner transactions succeed or they all fail.
18+
- Create a `Batch` transaction with multiple inner transactions, signed by multiple accounts, and submitted by a third party account.
19+
- Configure the `Batch` transaction to ensure atomicity, so that either all inner transactions succeed or they all fail.
2020

2121
## Prerequisites
2222

@@ -32,7 +32,7 @@ You can find the complete source code for this tutorial's examples in the [code
3232

3333
## Steps
3434

35-
The example in this tutorial demonstrates a scenario where Bob and Charlie both owe Alice 50 XRP each, and a third-party (such as a payment processor) submits the Batch transaction atomically to ensure Alice is paid by both parties.
35+
The example in this tutorial demonstrates a scenario where Bob and Charlie both owe Alice 50 XRP each, and a third-party (such as a payment processor) submits the `Batch` transaction atomically to ensure Alice is paid by both parties.
3636

3737
### 1. Install dependencies
3838

@@ -69,25 +69,25 @@ Next, prepare the inner transactions that will be included in the batch.
6969

7070
The first transaction sends a payment of 50 XRP from Charlie to Alice, and the second sends a payment of 50 XRP from Bob to Alice. Both transactions must include the `tfInnerBatchTxn` (0x40000000) flag to indicate that they are inner transactions of a batch.
7171

72-
Inner transactions must have a Fee of **0** and an empty string for the `SigningPubKey`. The outer Batch transaction handles the overall fee and signing for all inner transactions.
72+
Inner transactions must have a Fee of **0** and an empty string for the `SigningPubKey`. The outer `Batch` transaction handles the overall fee and signing for all inner transactions.
7373

7474
{% admonition type="info" name="Note" %}
75-
The `Fee` and `SigningPubKey` fields are omitted as the client library's _autofill_ functionality automatically populates these when submitting the Batch transaction.
75+
The `Fee` and `SigningPubKey` fields are omitted as the client library's _autofill_ functionality automatically populates these when submitting the `Batch` transaction.
7676

7777
You typically don't need to set these manually, but if you do, ensure `Fee` is set to 0 and `SigningPubKey` is an empty string.
7878
{% /admonition %}
7979

8080
### 4. Prepare Batch transaction
8181

82-
Create the Batch transaction and provide the inner transactions. The key fields to note are:
82+
Create the `Batch` transaction and provide the inner transactions. The key fields to note are:
8383

8484
| Field | Value |
8585
|:---------------- |:---------- |
8686
| TransactionType | The type of transaction, in this case `Batch`.|
87-
| Account | The wallet address of the account that is sending the Batch transaction. |
88-
| Flags | The flags for the Batch transaction. For this example the transaction is configured with the `tfAllOrNothing` (0x00010000) flag to ensure that either all inner transactions succeed or they all fail atomically. See [Batch Flags](../../../references/protocol/transactions/types/batch.md#batch-flags) for other options. |
87+
| Account | The wallet address of the account that is sending the `Batch` transaction. |
88+
| Flags | The flags for the `Batch` transaction. For this example the transaction is configured with the `tfAllOrNothing` (0x00010000) flag to ensure that either all inner transactions succeed or they all fail atomically. See [Batch Flags](../../../references/protocol/transactions/types/batch.md#batch-flags) for other options. |
8989
| RawTransactions | Contains the list of inner transactions to be applied. Must include a minimum of **2** transactions and a maximum of **8** transactions. These transactions can come from one account or multiple accounts. |
90-
| BatchSigners | The list of signatures required for the Batch transaction. This is required because there are multiple accounts' transactions included in the batch. |
90+
| BatchSigners | The list of signatures required for the `Batch` transaction. This is required because there are multiple accounts' transactions included in the batch. |
9191

9292
{% tabs %}
9393
{% tab label="Javascript" %}
@@ -99,20 +99,20 @@ Because we used `autofill`, the client library automatically fills in any missin
9999

100100
### 5. Gather batch signatures
101101

102-
To add the `BatchSigners` field, you need to collect signatures from each account that's sending a transaction within the batch. In this case we need two signatures, one from Charlie and one from Bob. Each sender must sign the Batch transaction to authorize their payment.
102+
To add the `BatchSigners` field, you need to collect signatures from each account that's sending a transaction within the batch. In this case we need two signatures, one from Charlie and one from Bob. Each sender must sign the `Batch` transaction to authorize their payment.
103103

104104
{% tabs %}
105105
{% tab label="Javascript" %}
106-
The **xrpl.js** library provides a helper function, `signMultiBatch()`, to sign the Batch transaction for each account.
106+
The **xrpl.js** library provides a helper function, `signMultiBatch()`, to sign the `Batch` transaction for each account.
107107

108-
Then, to combine the signatures into a single signed Batch transaction, use the `combineBatchSigners()` utility function.
108+
Then, to combine the signatures into a single signed `Batch` transaction, use the `combineBatchSigners()` utility function.
109109
{% code-snippet file="/_code-samples/batch/js/multiAccountBatch.js" language="js" from="// Gather batch signatures" to="// Submit" /%}
110110
{% /tab %}
111111
{% /tabs %}
112112

113113
### 6. Submit Batch transaction
114114

115-
With all the required signatures gathered, the third-party wallet can now submit the Batch transaction.
115+
With all the required signatures gathered, the third-party wallet can now submit the `Batch` transaction.
116116

117117
{% tabs %}
118118
{% tab label="Javascript" %}
@@ -122,7 +122,7 @@ With all the required signatures gathered, the third-party wallet can now submit
122122

123123
### 7. Check Batch transaction result
124124

125-
To check the result of the Batch transaction submission:
125+
To check the result of the `Batch` transaction submission:
126126

127127
{% tabs %}
128128
{% tab label="Javascript" %}
@@ -133,14 +133,14 @@ To check the result of the Batch transaction submission:
133133
The code checks for a `tesSUCCESS` result and displays the response details.
134134

135135
{% admonition type="warning" name="Warning" %}
136-
A `tesSUCCESS` result indicates that the Batch transaction was processed successfully, but does not guarantee the inner transactions succeeded. For example, see the [following transaction on the XRPL Explorer](https://devnet.xrpl.org/transactions/20CFCE5CF75E93E6D1E9C1E42F8E8C8C4CB1786A65BE23D2EA77EAAB65A455C5/simple).
136+
A `tesSUCCESS` result indicates that the `Batch` transaction was processed successfully, but does not guarantee the inner transactions succeeded. For example, see the [following transaction on the XRPL Explorer](https://devnet.xrpl.org/transactions/20CFCE5CF75E93E6D1E9C1E42F8E8C8C4CB1786A65BE23D2EA77EAAB65A455C5/simple).
137137
{% /admonition %}
138138

139-
Because the Batch transaction is configured with a `tfAllOrNothing` flag, if any inner transaction fails, **all** inner transactions wil fail, and only the Batch transaction fee is deducted from the **third-party wallet**.
139+
Because the `Batch` transaction is configured with a `tfAllOrNothing` flag, if any inner transaction fails, **all** inner transactions wil fail, and only the `Batch` transaction fee is deducted from the **third-party wallet**.
140140

141141
### 8. Verify inner transactions
142142

143-
Since there is no way to check the status of inner transactions in the Batch transaction result, you need to calculate the inner transaction hashes and look them up on the ledger:
143+
Since there is no way to check the status of inner transactions in the `Batch` transaction result, you need to calculate the inner transaction hashes and look them up on the ledger:
144144

145145
{% tabs %}
146146
{% tab label="Javascript" %}

0 commit comments

Comments
 (0)