Skip to content

Commit 44b5541

Browse files
committed
Add Batch transactions tutorials
1 parent 1e09559 commit 44b5541

File tree

9 files changed

+815
-2
lines changed

9 files changed

+815
-2
lines changed

_code-samples/batch/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Batch
22

3-
Code samples showing how to create and submit a [Batch transaction](../../docs/concepts/transactions/batch-transactions.md).
4-
Both for simple and multi account batch transactions.
3+
Code samples showing how to create and submit a [Batch transaction](https://xrpl.org/docs/concepts/transactions/batch-transactions).
4+
5+
Both for single and multi account batch transactions.

_code-samples/batch/js/README.md

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
# Send a Batch Transaction
2+
3+
Code samples showing how to create and submit a [Batch transaction](https://xrpl.org/docs/concepts/transactions/batch-transactions) with Javascript.
4+
5+
Both for single and multi account batch transactions.
6+
7+
## Single Account Batch Transaction
8+
9+
Quick setup and usage:
10+
11+
```sh
12+
npm install xrpl
13+
node singleAccountBatch.js
14+
```
15+
16+
The script should output the following:
17+
18+
```sh
19+
Funding new wallets from faucet...
20+
Sender: raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e, Balance: 100 XRP
21+
Wallet1: r4JMmKToZRMVT3mGWPnKHFEHsSMQEWigLC, Balance: 100 XRP
22+
Wallet2: rKfPgHASYuttoF1HfU56V31WbJvZn3w8xn, Balance: 100 XRP
23+
24+
Creating batch transaction:
25+
{
26+
"TransactionType": "Batch",
27+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
28+
"Flags": 65536,
29+
"RawTransactions": [
30+
{
31+
"RawTransaction": {
32+
"TransactionType": "Payment",
33+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
34+
"Destination": "r4JMmKToZRMVT3mGWPnKHFEHsSMQEWigLC",
35+
"Amount": "2000000",
36+
"Flags": 1073741824
37+
}
38+
},
39+
{
40+
"RawTransaction": {
41+
"TransactionType": "Payment",
42+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
43+
"Destination": "rKfPgHASYuttoF1HfU56V31WbJvZn3w8xn",
44+
"Amount": "5000000",
45+
"Flags": 1073741824
46+
}
47+
}
48+
]
49+
}
50+
51+
Submitting batch transaction...
52+
53+
Batch transaction submitted successfully!
54+
Result:
55+
{
56+
"close_time_iso": "2025-11-03T14:16:21Z",
57+
"ctid": "C00D458B00020002",
58+
"hash": "A93D3C2BDB5D600E592B64B84E66D789237D029267129EBC659EE483E532DD95",
59+
"ledger_hash": "BE6B7C12E551305F09E942D6FA3FC8546F024AE5C53FC495DA6ABF78461E7019",
60+
"ledger_index": 869771,
61+
"meta": {
62+
"AffectedNodes": [
63+
{
64+
"ModifiedNode": {
65+
"FinalFields": {
66+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
67+
"Balance": "99999996",
68+
"Flags": 0,
69+
"OwnerCount": 0,
70+
"Sequence": 869767
71+
},
72+
"LedgerEntryType": "AccountRoot",
73+
"LedgerIndex": "6238B6901FEBD1492C03546C7965A01F184C4E37B696304B86F78F4ADB7831B1",
74+
"PreviousFields": {
75+
"Balance": "100000000",
76+
"Sequence": 869766
77+
},
78+
"PreviousTxnID": "559F102041D84FF9DA17483355C3C96A0F8923D9C9C7971BBB15C972DD1F37D6",
79+
"PreviousTxnLgrSeq": 869766
80+
}
81+
}
82+
],
83+
"TransactionIndex": 2,
84+
"TransactionResult": "tesSUCCESS"
85+
},
86+
"tx_json": {
87+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
88+
"Fee": "4",
89+
"Flags": 65536,
90+
"LastLedgerSequence": 869789,
91+
"RawTransactions": [
92+
{
93+
"RawTransaction": {
94+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
95+
"Amount": "2000000",
96+
"Destination": "r4JMmKToZRMVT3mGWPnKHFEHsSMQEWigLC",
97+
"Fee": "0",
98+
"Flags": 1073741824,
99+
"Sequence": 869767,
100+
"SigningPubKey": "",
101+
"TransactionType": "Payment"
102+
}
103+
},
104+
{
105+
"RawTransaction": {
106+
"Account": "raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e",
107+
"Amount": "5000000",
108+
"Destination": "rKfPgHASYuttoF1HfU56V31WbJvZn3w8xn",
109+
"Fee": "0",
110+
"Flags": 1073741824,
111+
"Sequence": 869768,
112+
"SigningPubKey": "",
113+
"TransactionType": "Payment"
114+
}
115+
}
116+
],
117+
"Sequence": 869766,
118+
"SigningPubKey": "EDFECFB87A29F93E52BBA0BA5A14A59B520BB0E39F33943A2FDC1101D34349270D",
119+
"TransactionType": "Batch",
120+
"TxnSignature": "E08E300BDE1700C7CC27F3DA9B784907F637518E1C7E0978E57BFE5D1511A3B6A4269235FC2D9EAA550182A5F2B59415A442CE59555B9B9A0A79AB4030C9F701",
121+
"ctid": "C00D458B00020002",
122+
"date": 815494581,
123+
"ledger_index": 869771
124+
},
125+
"validated": true
126+
}
127+
128+
Final balances after batch transaction:
129+
Sender: raNwujquxJ7QTLhfbkKN6sZa7RBPHV671e, Balance: 92.999996 XRP
130+
Wallet1: r4JMmKToZRMVT3mGWPnKHFEHsSMQEWigLC, Balance: 102 XRP
131+
Wallet2: rKfPgHASYuttoF1HfU56V31WbJvZn3w8xn, Balance: 105 XRP
132+
133+
Transaction URL:
134+
https://devnet.xrpl.org/transactions/A93D3C2BDB5D600E592B64B84E66D789237D029267129EBC659EE483E532DD95
135+
```
136+
137+
## Multi-Account Batch Transaction
138+
139+
```sh
140+
npm install xrpl
141+
node multiAccountBatch.js
142+
```
143+
144+
The script should output the following:
145+
146+
```sh
147+
Funding new wallets from faucet...
148+
Alice: rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa, Balance: 100 XRP
149+
Bob: rKPUDuS2jQNpAMhkNncqC9rKJDpL2gXDN7, Balance: 100 XRP
150+
Charlie: rnz3Da7phfR6tgTZoPYF5psYTiHTshTB8K, Balance: 100 XRP
151+
Third-party wallet: rU8LsCmVjSdf7hSmiGBtBDtt2WhHxp7Zpc, Balance: 100 XRP
152+
153+
Creating batch transaction:
154+
{
155+
"TransactionType": "Batch",
156+
"Account": "rU8LsCmVjSdf7hSmiGBtBDtt2WhHxp7Zpc",
157+
"Flags": 65536,
158+
"RawTransactions": [
159+
{
160+
"RawTransaction": {
161+
"TransactionType": "Payment",
162+
"Account": "rnz3Da7phfR6tgTZoPYF5psYTiHTshTB8K",
163+
"Destination": "rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa",
164+
"Amount": "50000000",
165+
"Flags": 1073741824
166+
}
167+
},
168+
{
169+
"RawTransaction": {
170+
"TransactionType": "Payment",
171+
"Account": "rKPUDuS2jQNpAMhkNncqC9rKJDpL2gXDN7",
172+
"Destination": "rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa",
173+
"Amount": "50000000",
174+
"Flags": 1073741824
175+
}
176+
}
177+
]
178+
}
179+
180+
Submitting batch transaction...
181+
182+
Batch transaction submitted successfully!
183+
Result:
184+
{
185+
"close_time_iso": "2025-11-03T14:15:00Z",
186+
"ctid": "C00D457000000002",
187+
"hash": "8CBCCD88B8ABC248797B84ABB92066961C1CB5FE75ACE2115ADCA6B74C85993A",
188+
"ledger_hash": "2217A0DBB38B870187B412533B939724095359A050B21E071A2A114BF57CFB60",
189+
"ledger_index": 869744,
190+
"meta": {
191+
"AffectedNodes": [
192+
{
193+
"ModifiedNode": {
194+
"FinalFields": {
195+
"Account": "rU8LsCmVjSdf7hSmiGBtBDtt2WhHxp7Zpc",
196+
"Balance": "99999994",
197+
"Flags": 0,
198+
"OwnerCount": 0,
199+
"Sequence": 869743
200+
},
201+
"LedgerEntryType": "AccountRoot",
202+
"LedgerIndex": "1E9BA043B9C6518582D0FF73A08DCD8B6958195735086CF7295E5EB6433FB453",
203+
"PreviousFields": {
204+
"Balance": "100000000",
205+
"Sequence": 869742
206+
},
207+
"PreviousTxnID": "F7019BC55D80438FDDB01C2549CCC3F7DAF9791F8645E0269D63979EAEC5BBA6",
208+
"PreviousTxnLgrSeq": 869742
209+
}
210+
}
211+
],
212+
"TransactionIndex": 0,
213+
"TransactionResult": "tesSUCCESS"
214+
},
215+
"tx_json": {
216+
"Account": "rU8LsCmVjSdf7hSmiGBtBDtt2WhHxp7Zpc",
217+
"BatchSigners": [
218+
{
219+
"BatchSigner": {
220+
"Account": "rnz3Da7phfR6tgTZoPYF5psYTiHTshTB8K",
221+
"SigningPubKey": "EDC566D7DA8186BBD30DDAE1FB770FCE7F248949194E1A2E70B18CFA060B140B59",
222+
"TxnSignature": "31639BFA1359DD24345776EAEEACCF61C1CDC792988679263D113E80A22D837E20ACD2B25E482FCA769990C004D747836370C6BAD14524559639BBEBA5813002"
223+
}
224+
},
225+
{
226+
"BatchSigner": {
227+
"Account": "rKPUDuS2jQNpAMhkNncqC9rKJDpL2gXDN7",
228+
"SigningPubKey": "EDEF1966B325000407940E4C0792E3CCC3E27F51D132BDC53DCC2B1998E7C32A34",
229+
"TxnSignature": "6BF9860B0E2E134FB302329D711BAA7B6314395D39523982DBBC037E84FB17AB5E8E736DB3DB0019B4477686AF2D91E5D2B49409698A95219376B2E318D3E501"
230+
}
231+
}
232+
],
233+
"Fee": "6",
234+
"Flags": 65536,
235+
"LastLedgerSequence": 869762,
236+
"RawTransactions": [
237+
{
238+
"RawTransaction": {
239+
"Account": "rnz3Da7phfR6tgTZoPYF5psYTiHTshTB8K",
240+
"Amount": "50000000",
241+
"Destination": "rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa",
242+
"Fee": "0",
243+
"Flags": 1073741824,
244+
"Sequence": 869740,
245+
"SigningPubKey": "",
246+
"TransactionType": "Payment"
247+
}
248+
},
249+
{
250+
"RawTransaction": {
251+
"Account": "rKPUDuS2jQNpAMhkNncqC9rKJDpL2gXDN7",
252+
"Amount": "50000000",
253+
"Destination": "rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa",
254+
"Fee": "0",
255+
"Flags": 1073741824,
256+
"Sequence": 869738,
257+
"SigningPubKey": "",
258+
"TransactionType": "Payment"
259+
}
260+
}
261+
],
262+
"Sequence": 869742,
263+
"SigningPubKey": "ED2B56D6FB4E8C236A6B07E8D8AD9A4938606144E31779918F99525CA6B3C56664",
264+
"TransactionType": "Batch",
265+
"TxnSignature": "9C51C1F2CB0E8BCEA1FADD3992249DE72AC46FC86AB2FB023A597FBD5C4CCB3337967E9AAFFB5F1C0CBC91128F3FD194F78F207E461BE1FF906C496B94EC410E",
266+
"ctid": "C00D457000000002",
267+
"date": 815494500,
268+
"ledger_index": 869744
269+
},
270+
"validated": true
271+
}
272+
273+
Final balances after batch transaction:
274+
Alice: rfCBfRGpcGJLwdbfz1M6HYoAL8nZyHRHHa, Balance: 200 XRP
275+
Bob: rKPUDuS2jQNpAMhkNncqC9rKJDpL2gXDN7, Balance: 50 XRP
276+
Charlie: rnz3Da7phfR6tgTZoPYF5psYTiHTshTB8K, Balance: 50 XRP
277+
Third-party wallet: rU8LsCmVjSdf7hSmiGBtBDtt2WhHxp7Zpc, Balance: 99.999994 XRP
278+
279+
Transaction URL:
280+
https://devnet.xrpl.org/transactions/8CBCCD88B8ABC248797B84ABB92066961C1CB5FE75ACE2115ADCA6B74C85993A
281+
```

0 commit comments

Comments
 (0)