Files
xrpl-dev-portal/content/concepts/introduction/txn-and-requests.md
2022-11-14 13:16:14 -08:00

4.2 KiB

html, parent, blurb, labels
html parent blurb labels
txn-and-requests.html intro-to-xrpl.html All interactions with the ledger are either transactions or requests.
Blockchain

Transactions and Requests

All interactions with the XRP Ledger involve either sending a transaction that makes changes to the ledger or sending a request for information from the ledger.

How Do Transactions Work?

You execute a transaction by sending a REST command to the XRP Ledger and waiting for the response. The command syntax is always the same for every transaction.

You must always provide the TransactionType and the public address of the Account making the transaction.

Two required fields are the Fee for the transaction and the next Sequence number for transactions from the account. These fields can be filled in automatically by the ledger server when you submit the transaction.

Specific transactions also have required fields specific to the transaction type. For example, a Payment transaction requires an Amount value (in drops, or millionths of an XRP) and a Destination public address to which the funds are credited.

Here is a sample transaction in JSON format. This transaction transfers 1 XRP from account rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn to destination account ra5nK24KXen9AHvsdFTKHSANinZseWnPcX.

{
  "TransactionType": "Payment",
  "Account": rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn,
  "Amount": 1000000,
  "Destination": ra5nK24KXen9AHvsdFTKHSANinZseWnPcX
}

Optional fields are available for all transactions, with additional fields available for specific transactions. You can include as many optional fields as you need, but do not have to include every field in every transaction.

You send the transaction to the ledger as a RESTful command from JavaScript, Python, the command line, or any compatible service. The rippled server proposes the transaction to the ledger. When 80% of the validators approve the transaction, it is recorded as part of the permanent ledger. The ledger returns the results of the transaction.

For more information on Transactions, see Transactions.

How Do Requests Work?

Requests are similar to transactions, but they do not make changes to the ledger.

The fields you send vary with the type of information you request. They typically have several optional fields, but only a few required fields.

This is a sample request in JSON format. This request gets the current account information for the account number you provide.

{
  "command": "account_info",
  "account": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn"
}

The request returns the information in a format appropriate for the language you used to make the request. Here is an example of the response for an account information request in JSON format.

{
    "result": {
        "account_data": {
            "Account": "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn",
            "Balance": "999999999960",
            "Flags": 8388608,
            "LedgerEntryType": "AccountRoot",
            "OwnerCount": 0,
            "PreviousTxnID": "4294BEBE5B569A18C0A2702387C9B1E7146DC3A5850C1E87204951C6FDAA4C42",
            "PreviousTxnLgrSeq": 3,
            "Sequence": 6,
            "index": "92FA6A9FC8EA6018D5D16532D7795C91BFB0831355BDFDA177E86C8BF997985F"
        },
        "ledger_current_index": 4,
        "queue_data": {
            "auth_change_queued": true,
            "highest_sequence": 10,
            "lowest_sequence": 6,
            "max_spend_drops_total": "500",
            "transactions": [
                {
                    "auth_change": false,
                    "fee": "100",
                    "fee_level": "2560",
                    "max_spend_drops": "100",
                    "seq": 6
                },
                ... (trimmed for length) ...
                {
                    "LastLedgerSequence": 10,
                    "auth_change": true,
                    "fee": "100",
                    "fee_level": "2560",
                    "max_spend_drops": "100",
                    "seq": 10
                }
            ],
            "txn_count": 5
        },
        "status": "success",
        "validated": false
    }
}