Handy_4ndy's profile banner
Handy_4ndy's profile picture

Handy_4ndy

@Handy_4ndy

February 13
Founder / Developer
Manchester
3 min read
Lock In
3

Batch on XRPL Devnet

Updated

Batch

Batch on DevnetBatch on Devnet

Now Available on Devnet

The rippled update to 2.5.0 is packed with exciting new features available on devnet today. Two that I've been eagerly awaiting are Batch and Token Escrows, so naturally, I've been diving into both on devnet learning what I can about these exciting addition's to the XRP Ledger.

Following the same theme as the Hook explainers, I'm going to quickly run through Batch using XRPLWin's Devnet dashboard. Here, you can enter devnet credentials to submit transactions with ease and observe the transaction flow.

Getting Started

If you need devnet credentials, generate and export up to 5 funded devnet accounts HERE. With your devnet credentials, head over to the Raw Transaction sender and sign in (switch seed algorithm to ed25519).

Devnet Sign inDevnet Sign in

Below is a template of a Batch transaction that includes two inner transactions. We'll dive deeper into this further down. Copy the raw JSON template into XRPLWin's transaction sender, enter your Account, hit submit, and see what happens.

{
  "TransactionType": "Batch",
  "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
  "Flags": 65536,
  "RawTransactions": [
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rpZpYRvMpgqAgd6wWYnXhwR4FyQdbyqSUc",
            "Amount": "5000000", 
            "Fee": "0",
            "SigningPubKey": ""
          }
        },
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rBSQzsQYxgFnHNnFVKM1ZuGLRUikib1dLx",
            "Amount": "5000000",
            "Fee": "0",
            "SigningPubKey": ""
          }
        }
    ]
}

If all goes well, congratulations! You've just completed your first Batch transaction!

Batch tesSUCCESSBatch tesSUCCESS

The Batch transaction contained two inner transactions, each sending a Payment of 5 XRP with the tfAllOrNothing flag. This flag requires all inner transactions to succeed otherwise, none are submitted. Here are the available flags for Batch transactions:

// Batch transaction flags
const BatchFlags = {
  tfAllOrNothing: 0x00010000,      // 65536
  tfOnlyOne: 0x00020000,           // 131072
  tfUntilFailure: 0x00040000,      // 262144
  tfIndependent: 0x00080000,       // 524288
}

// Global flag for inner batch transactions
const GlobalFlags = {
  tfInnerBatchTxn: 0x40000000      // 1073741824
}

Flag DocumentationFlag Documentation

These flags allow you to modify how the Batch transaction handles the completion of inner transactions. Each inner transaction includes the tfInnerBatchTxn flag. Let's copy the following template into the Raw Transaction sender and modify the flags to change the outcome. Batch supports multiple transaction types, but we'll stick with payments for simplicity in this tutorial.

{
  "TransactionType": "Batch",
  "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
  "Flags": 65536,
  "RawTransactions": [
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rpZpYRvMpgqAgd6wWYnXhwR4FyQdbyqSUc",
            "Amount": "5000000", 
            "Fee": "0",
            "SigningPubKey": ""
          }
        },
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rBSQzsQYxgFnHNnFVKM1ZuGLRUikib1dLx",
            "Amount": "5000000",
            "Fee": "0",
            "SigningPubKey": ""
          }
        },
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rpZpYRvMpgqAgd6wWYnXhwR4FyQdbyqSUc",
            "Amount": "50000000000", 
            "Fee": "0",
            "SigningPubKey": ""
          }
        },
        {
          "RawTransaction": {
            "TransactionType": "Payment",
            "Flags": 1073741824,
            "Account": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
            "Destination": "rBSQzsQYxgFnHNnFVKM1ZuGLRUikib1dLx",
            "Amount": {
                    "currency": "XRM",
                    "issuer": "rJn5PKZzyVRGzTgFGFuYSeU4WpBqkvo4AB",
                    "value": "100"
                  },
            "Fee": "0",
            "SigningPubKey": ""
          }
        }
    ]
}

Simply adjusting the Batch transaction flag significantly changes the outcome. Add multiple transaction types, and you have a tool to abstract some complexities with a secure on-chain solution.

tfIndependant resulttfIndependant result

Note that this is an example of one account submitting and signing all transactions (Outer and Inner transactions). If you're interested in exploring batch signers, check out the helpful video from @markibanez, CTO of Gen3 Games, in the sources below.

Sources

XLS-0056d-batch

XRPLWin Devnet

Devnet Credentials

YouTube

BatchXRPLedgerBlockchainXRPLWinXspence