CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-xrpl-py

A complete Python library for interacting with the XRP Ledger blockchain, providing transaction creation, account management, and comprehensive XRPL protocol support

Overview
Eval results
Files

transactions.mddocs/

Transaction Management

Create, sign, submit, and manage XRPL transactions with full support for all transaction types including payments, offers, escrows, NFTs, AMM operations, and cross-chain bridges. The transaction module provides the complete lifecycle management for XRPL transactions.

Capabilities

Transaction Signing

Sign transactions with wallets using single or multisign approaches.

from xrpl import transaction

def sign(transaction, wallet, multisign: bool = False):
    """
    Sign a transaction with a wallet.
    
    Args:
        transaction: Transaction object to sign
        wallet: Wallet object containing private key
        multisign: Whether to create a multisign signature
        
    Returns:
        Signed transaction object with signature
    """

def multisign(transaction, wallet):
    """
    Add a multisign signature to a transaction.
    
    Args:
        transaction: Transaction object to multisign
        wallet: Wallet object for signing
        
    Returns:
        Transaction with added multisign signature
    """

Transaction Submission

Submit transactions to the XRPL network with various submission strategies.

def submit(transaction, client, fail_hard: bool = False):
    """
    Submit a signed transaction to the network.
    
    Args:
        transaction: Signed transaction object
        client: XRPL client for network communication
        fail_hard: Whether to fail hard on submission errors
        
    Returns:
        Submission response from the network
    """

def submit_and_wait(
    transaction, 
    client, 
    wallet, 
    autofill: bool = True, 
    check_fee: bool = True
):
    """
    Sign, submit, and wait for transaction validation.
    
    Args:
        transaction: Transaction object to submit
        client: XRPL client for network communication
        wallet: Wallet for signing
        autofill: Whether to auto-populate transaction fields
        check_fee: Whether to validate transaction fee
        
    Returns:
        Final transaction result after validation
    """

def sign_and_submit(
    transaction, 
    client, 
    wallet, 
    autofill: bool = True, 
    check_fee: bool = True
):
    """
    Sign and submit a transaction in one operation.
    
    Args:
        transaction: Transaction object to submit
        client: XRPL client for network communication
        wallet: Wallet for signing
        autofill: Whether to auto-populate transaction fields
        check_fee: Whether to validate transaction fee
        
    Returns:
        Submission response from the network
    """

Transaction Preparation

Automatically populate transaction fields and validate transactions before submission.

def autofill(transaction, client):
    """
    Auto-populate transaction fields like sequence, fee, and last ledger sequence.
    
    Args:
        transaction: Transaction object to autofill
        client: XRPL client for fetching current ledger info
        
    Returns:
        Transaction with populated fields
    """

def autofill_and_sign(transaction, client, wallet):
    """
    Autofill transaction fields and sign in one operation.
    
    Args:
        transaction: Transaction object to prepare
        client: XRPL client for network communication
        wallet: Wallet for signing
        
    Returns:
        Signed transaction with autofilled fields
    """

Transaction Simulation and Analysis

Test transactions and analyze their effects before submission.

def simulate(transaction, client):
    """
    Simulate transaction execution without submitting to ledger.
    
    Args:
        transaction: Transaction object to simulate
        client: XRPL client for simulation
        
    Returns:
        Simulation results showing expected effects
    """

def transaction_json_to_binary_codec_form(txn_json: dict) -> dict:
    """
    Convert transaction JSON to binary codec form.
    
    Args:
        txn_json: Transaction as JSON dictionary
        
    Returns:
        Transaction in binary codec format
    """

Batch Operations

Handle multiple transactions and batch signing operations.

def sign_multiaccount_batch(batch_txns: list, wallet):
    """
    Sign a batch of transactions with one wallet.
    
    Args:
        batch_txns: List of transaction objects to sign
        wallet: Wallet for signing all transactions
        
    Returns:
        List of signed transactions
    """

def combine_batch_signers(batch_signers: list) -> list:
    """
    Combine multiple batch signer arrays.
    
    Args:
        batch_signers: List of signer arrays to combine
        
    Returns:
        Combined list of signers
    """

Common Transaction Types

Payment Transactions

from xrpl.models.transactions import Payment
from xrpl.models.amounts import IssuedCurrencyAmount

# XRP payment
payment = Payment(
    account="rSender...",
    destination="rReceiver...",
    amount="1000000"  # 1 XRP in drops
)

# Issued currency payment  
payment = Payment(
    account="rSender...",
    destination="rReceiver...",
    amount=IssuedCurrencyAmount(
        currency="USD",
        value="100.50",
        issuer="rIssuer..."
    )
)

Offer Transactions

from xrpl.models.transactions import OfferCreate, OfferCancel

# Create a currency exchange offer
offer = OfferCreate(
    account="rTrader...",
    taker_gets="1000000",  # 1 XRP
    taker_pays=IssuedCurrencyAmount(
        currency="USD", 
        value="0.50",
        issuer="rIssuer..."
    )
)

# Cancel an existing offer
cancel = OfferCancel(
    account="rTrader...",
    offer_sequence=12345
)

Trust Line Transactions

from xrpl.models.transactions import TrustSet
from xrpl.models.currencies import IssuedCurrency

# Create/modify a trust line
trust_set = TrustSet(
    account="rAccount...",
    limit_amount=IssuedCurrencyAmount(
        currency="USD",
        value="1000",
        issuer="rIssuer..."
    )
)

Usage Examples

Basic Transaction Workflow

from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment
from xrpl import transaction

# Setup
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
wallet = Wallet.from_seed("sEdT...")

# Create payment
payment_tx = Payment(
    account=wallet.address,
    destination="rReceiver...",
    amount="1000000"  # 1 XRP
)

# Method 1: Step-by-step
autofilled_tx = transaction.autofill(payment_tx, client)
signed_tx = transaction.sign(autofilled_tx, wallet)
result = transaction.submit(signed_tx, client)

# Method 2: All-in-one (recommended)
result = transaction.submit_and_wait(payment_tx, client, wallet)
print(f"Transaction result: {result.result}")
print(f"Transaction hash: {result.result['hash']}")

Advanced Transaction Management

from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment, OfferCreate
from xrpl import transaction
import asyncio

def prepare_and_submit_transaction(tx, client, wallet):
    """Prepare and submit a transaction with error handling."""
    
    try:
        # Simulate first to check for issues
        print("Simulating transaction...")
        sim_result = transaction.simulate(tx, client)
        print(f"Simulation result: {sim_result}")
        
        # Submit if simulation successful
        print("Submitting transaction...")
        result = transaction.submit_and_wait(tx, client, wallet, check_fee=True)
        
        if result.is_successful():
            print(f"✅ Transaction successful: {result.result['hash']}")
            return result
        else:
            print(f"❌ Transaction failed: {result.result}")
            return None
            
    except Exception as e:
        print(f"❌ Error: {e}")
        return None

# Usage
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
wallet = Wallet.from_seed("sEdT...")

payment = Payment(
    account=wallet.address,
    destination="rReceiver...",
    amount="1000000"
)

result = prepare_and_submit_transaction(payment, client, wallet)

Multisign Transaction Workflow

from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment
from xrpl import transaction

# Setup multisign scenario
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
wallet1 = Wallet.from_seed("sEdT1...")
wallet2 = Wallet.from_seed("sEdT2...")

# Create transaction requiring multiple signatures
payment = Payment(
    account="rMultisigAccount...",  # Account with signer list
    destination="rReceiver...",
    amount="5000000"  # 5 XRP
)

# Autofill the transaction
autofilled_tx = transaction.autofill(payment, client)

# First signer
signed_tx1 = transaction.multisign(autofilled_tx, wallet1)

# Second signer adds their signature
signed_tx2 = transaction.multisign(signed_tx1, wallet2)

# Submit the multisigned transaction
from xrpl.models.requests import SubmitMultisigned
submit_request = SubmitMultisigned(tx_json=signed_tx2)
result = client.request(submit_request)
print(f"Multisign result: {result}")

Batch Transaction Processing

from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment, Batch
from xrpl import transaction

def process_payment_batch(payments: list, client, wallet):
    """Process multiple payments efficiently."""
    
    # Method 1: Individual transactions
    results = []
    for payment in payments:
        try:
            result = transaction.submit_and_wait(payment, client, wallet)
            results.append(result)
            print(f"Payment to {payment.destination}: {result.is_successful()}")
        except Exception as e:
            print(f"Failed payment to {payment.destination}: {e}")
            results.append(None)
    
    return results

# Method 2: Using batch transactions (if supported)
def create_batch_transaction(payments: list, account: str):
    """Create a batch transaction containing multiple payments."""
    
    batch = Batch(
        account=account,
        batch=payments
    )
    return batch

# Usage
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
wallet = Wallet.from_seed("sEdT...")

payments = [
    Payment(account=wallet.address, destination="rAddr1...", amount="1000000"),
    Payment(account=wallet.address, destination="rAddr2...", amount="2000000"),
    Payment(account=wallet.address, destination="rAddr3...", amount="3000000"),
]

# Process individually
results = process_payment_batch(payments, client, wallet)

# Or as batch (if network supports it)
batch_tx = create_batch_transaction(payments, wallet.address)
batch_result = transaction.submit_and_wait(batch_tx, client, wallet)

Asynchronous Transaction Operations

import asyncio
from xrpl.asyncio.clients import AsyncJsonRpcClient
from xrpl.asyncio import transaction
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment

async def submit_transactions_async(transactions: list, client, wallet):
    """Submit multiple transactions concurrently."""
    
    # Create submission tasks
    tasks = []
    for tx in transactions:
        task = transaction.submit_and_wait(tx, client, wallet)
        tasks.append(task)
    
    # Wait for all to complete
    results = await asyncio.gather(*tasks, return_exceptions=True)
    
    # Process results
    successful = 0
    for i, result in enumerate(results):
        if isinstance(result, Exception):
            print(f"Transaction {i} failed: {result}")
        elif result.is_successful():
            print(f"Transaction {i} successful: {result.result['hash']}")
            successful += 1
        else:
            print(f"Transaction {i} failed: {result.result}")
    
    print(f"Successfully submitted {successful}/{len(transactions)} transactions")
    return results

async def main():
    client = AsyncJsonRpcClient("https://s.altnet.rippletest.net:51234")
    wallet = Wallet.from_seed("sEdT...")
    
    # Create multiple payments
    payments = [
        Payment(account=wallet.address, destination=f"rAddr{i}...", amount=str(i * 1000000))
        for i in range(1, 6)
    ]
    
    try:
        results = await submit_transactions_async(payments, client, wallet)
    finally:
        await client.close()

# Run async example
asyncio.run(main())

Exceptions

class XRPLReliableSubmissionException(XRPLException):
    """Exception for reliable submission failures during transaction processing."""

Install with Tessl CLI

npx tessl i tessl/pypi-xrpl-py

docs

accounts.md

clients.md

core.md

index.md

ledger.md

models.md

transactions.md

utils.md

wallets.md

tile.json