xrpl

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 9 Imported by: 0

README

xrpl

This is the core package of the SDK. It contains everything needed to construct, sign, and submit transactions to the XRP Ledger, query ledger state, and manage accounts — built on top of the lower-level address-codec, keypairs, and binary-codec packages.

Package Structure

xrpl/
├── transaction/        # All transaction types and shared transaction logic
├── wallet/             # Wallet creation, derivation, and offline signing
├── rpc/                # Synchronous JSON-RPC client
├── websocket/          # Asynchronous WebSocket client
├── queries/            # Request/response types for all rippled API methods
├── ledger-entry-types/ # Structs for ledger objects (Offer, AccountRoot, etc.)
├── currency/           # Currency amount utilities
├── hash/               # Transaction hash utilities
├── common/             # Shared constants and helpers
├── flag/               # Transaction flag definitions
├── time/               # XRPL epoch time utilities
├── multisign.go        # Multi-signature aggregation utility
└── interfaces/         # Shared interfaces (CryptoImplementation, etc.)

transaction/

All XRPL transaction types live here, one file per type. Every transaction embeds BaseTx and implements the Tx interface:

type Tx interface {
    TxType() TxType
}

BaseTx contains the fields common to every transaction:

Field Description
Account Sender's classic address
TransactionType e.g. Payment, OfferCreate, TrustSet
Fee Cost in drops (must be set before signing)
Sequence Account sequence number (0 if using a Ticket)
LastLedgerSequence Expiry ledger — always set to avoid stuck transactions
SigningPubKey Public key of the signer, included in the signed blob produced by wallet.Sign
TxnSignature Signature, included in the signed blob produced by wallet.Sign
Signers Multi-signature entries
Memos Arbitrary attached data
Flags Bitmask of transaction-specific flags

Each transaction type has a Flatten() FlatTransaction method that converts the struct to a map[string]any for JSON-RPC submission.

Available transaction types include: Payment, AccountSet, AccountDelete, TrustSet, OfferCreate, OfferCancel, EscrowCreate/Finish/Cancel, PaymentChannelCreate/Fund/Claim, NFTokenMint/Burn/CreateOffer/CancelOffer/AcceptOffer, AMMCreate/Deposit/Withdraw/Vote/Bid/Delete, CheckCreate/Cash/Cancel, TicketCreate, SignerListSet, SetRegularKey, DepositPreauth, DIDSet/Delete, OracleSet/Delete, XChain*, Batch, and more.


wallet/

Provides the Wallet struct for key management and offline signing.

type Wallet struct {
    PublicKey      string
    PrivateKey     string
    ClassicAddress types.Address
    Seed           string
}
Creation
// Random wallet (ED25519 or SECP256K1)
w, err := wallet.New(crypto.ED25519())

// From an existing seed
w, err := wallet.FromSeed(seed, "")
w, err := wallet.FromSecret(seed) // alias

// From a BIP-39 mnemonic (derives via m/44'/144'/0'/0/0)
w, err := wallet.FromMnemonic("word1 word2 ...")
Signing
// Single signature — returns the signed blob and its hash; flatTx is not mutated
txBlob, txHash, err := w.Sign(flatTx)

// Multi-signature — returns the signed blob and its hash; flatTx is not mutated
txBlob, txHash, err := w.Multisign(flatTx)

Sign internally calls binarycodec.EncodeForSigning to get the signing payload, signs it with keypairs.Sign, then calls binarycodec.Encode to produce the final blob.


rpc/

A synchronous HTTP JSON-RPC client. Best for one-off queries and simple transaction submission.

cfg := rpc.NewConfig("https://s.altnet.rippletest.net:51234")
client := rpc.NewClient(cfg)

// Submit a pre-signed blob
resp, err := client.SubmitTxBlob(txBlob, false)

// Submit and wait for ledger confirmation
txResp, err := client.SubmitTxBlobAndWait(txBlob, false)

The client automatically retries on HTTP 503 (up to 3 times with exponential backoff) and validates that submitted blobs contain a signature before sending.


websocket/

An asynchronous WebSocket client. Best for subscriptions, real-time monitoring, and applications that need to react to ledger events.

cfg := websocket.NewConfig("wss://s.altnet.rippletest.net:51233")
client, err := websocket.NewClient(cfg)

// Subscribe to ledger close events
err = client.SubscribeLedger()

// Read events from channels
ledger := <-client.GetLedgerClosedChannel()
tx     := <-client.GetTransactionChannel()

The WebSocket client manages connection lifecycle, request/response correlation by ID, and exposes typed channels for each stream type (ledger, transaction, validation, etc.).


queries/

Typed request and response structs for every rippled API method, organized by category:

Subdirectory Methods
account/ account_info, account_lines, account_offers, account_tx, etc.
ledger/ ledger, ledger_closed, ledger_current, ledger_data, ledger_entry
transactions/ submit, submit_multisigned, tx, transaction_entry
server/ server_info, server_state, fee
subscription/ Stream types for ledger, transaction, and validation subscriptions

multisign.go

Top-level utility for combining multiple individual multi-signature blobs into a single transaction ready for submission:

// Each blob must be produced by wallet.Multisign
finalBlob, err := xrpl.Multisign(blob1, blob2, blob3)

Signers are sorted by account ID bytes (ascending) as required by the XRPL protocol before the final blob is encoded.

Documentation

Overview

Package xrpl provides utilities for working with the XRP Ledger.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTxToMultisign is returned when no transaction blobs are provided to Multisign.
	ErrNoTxToMultisign = errors.New("no transaction to multisign")
	// ErrMultisignNonEmptySigningPubKey is returned when SigningPubKey is not empty
	// on one or more transactions passed to Multisign, it must be an empty string for all.
	ErrMultisignNonEmptySigningPubKey = errors.New("SigningPubKey must be an empty string for all transactions when multisigning")
	// ErrMultisignTxNotEqual is returned when transaction blobs passed to Multisign
	// do not represent the same transaction (ignoring the Signers field).
	ErrMultisignTxNotEqual = errors.New("all transactions to multisign must be equal except for the Signers field")
	// ErrMultisignInvalidSignature is returned when a signer signature is invalid
	// for one or more transactions passed to Multisign.
	ErrMultisignInvalidSignature = errors.New("invalid multisign signer signature")
	// ErrInvalidSigner is returned when a signer entry is malformed.
	ErrInvalidSigner = errors.New("invalid signer")
)

Functions

func Multisign

func Multisign(blobs ...string) (string, error)

Multisign is a utility for signing a transaction offline. It takes a list of transaction blobs and returns the multisigned transaction blob. These transaction blobs must be signed with the wallet.Multisign method. They cannot contain SigningPubKey, otherwise the transaction will fail to submit. All blobs must represent the same transaction (excluding Signers); otherwise ErrMultisignTxNotEqual is returned. Every signer signature must be valid; otherwise ErrMultisignInvalidSignature is returned. If an error occurs, it will return an error.

func SortByAccountID added in v0.2.0

func SortByAccountID[T any](items []T, account func(T) (string, error)) error

SortByAccountID sorts items in place by the decoded bytes of each item's classic XRPL account address. Use it for canonical signer ordering when different signer representations store the account in different fields. The account function extracts the classic address from an item and may return an error when the item does not contain one. SortByAccountID validates and decodes every account before sorting, so items stay in their original order if extraction or decoding fails.

func SortSigners added in v0.1.16

func SortSigners(signers []any) error

SortSigners sorts signers ascending by their decoded account ID bytes.

Types

This section is empty.

Directories

Path Synopsis
Package currency provides utilities for working with XRP native currency conversions and calculations.
Package currency provides utilities for working with XRP native currency conversions and calculations.
Package faucet provides utilities to interact with an XRP testnet faucet.
Package faucet provides utilities to interact with an XRP testnet faucet.
Package flag provides utility functions for working with bitwise flags.
Package flag provides utility functions for working with bitwise flags.
Package hash provides constants for prefixes used in hashing XRPL objects.
Package hash provides constants for prefixes used in hashing XRPL objects.
internal
clientconfig
Package clientconfig contains shared helpers for XRPL client configuration.
Package clientconfig contains shared helpers for XRPL client configuration.
clientconfig/testutil
Package testutil exposes helpers for tests that exercise clientconfig.
Package testutil exposes helpers for tests that exercise clientconfig.
Package ledger defines types for ledger entries in the XRP Ledger.
Package ledger defines types for ledger entries in the XRP Ledger.
queries
account/types
Package types contains data structures for account query types.
Package types contains data structures for account query types.
account/v1
Package v1 contains version 1 account queries for XRPL.
Package v1 contains version 1 account queries for XRPL.
amm
Package amm contains amm-related queries for XRPL.
Package amm contains amm-related queries for XRPL.
channel
Package channel provides commands to query XRPL payment channel methods.
Package channel provides commands to query XRPL payment channel methods.
channel/v1
Package v1 contains version 1 payment channel queries for XRPL.
Package v1 contains version 1 payment channel queries for XRPL.
clio
Package clio provides types and requests for CLIO-specific XRPL queries.
Package clio provides types and requests for CLIO-specific XRPL queries.
clio/types
Package types contains data structures for CLIO server query types.
Package types contains data structures for CLIO server query types.
clio/v1
Package v1 contains version 1 CLIO server queries for XRPL.
Package v1 contains version 1 CLIO server queries for XRPL.
common
Package common provides shared types for XRPL ledger specifiers and parsing utilities.
Package common provides shared types for XRPL ledger specifiers and parsing utilities.
ledger
Package ledger contains ledger-related queries for XRPL.
Package ledger contains ledger-related queries for XRPL.
ledger/types
Package types contains types for ledger query responses.
Package types contains types for ledger query responses.
ledger/v1
Package v1 contains version 1 ledger queries for XRPL.
Package v1 contains version 1 ledger queries for XRPL.
nft
Package nft provides commands to query XRPL NFT-related methods.
Package nft provides commands to query XRPL NFT-related methods.
nft/v1
Package v1 provides version 1 types and methods for NFT buy offers queries.
Package v1 provides version 1 types and methods for NFT buy offers queries.
oracle
Package oracle contains oracle-related queries for XRPL.
Package oracle contains oracle-related queries for XRPL.
oracle/types
Package types contains data structures for oracle query types.
Package types contains data structures for oracle query types.
path
Package path contains path finding and order book queries for XRPL.
Package path contains path finding and order book queries for XRPL.
path/types
Package types contains data structures for path finding query types.
Package types contains data structures for path finding query types.
path/v1
Package v1 contains version 1 path finding queries for XRPL.
Package v1 contains version 1 path finding queries for XRPL.
server
Package server contains server-related queries for XRPL.
Package server contains server-related queries for XRPL.
server/types
Package types provides data structures for server query responses.
Package types provides data structures for server query responses.
subscription
Package subscribe contains subscription functionality for XRPL streams.
Package subscribe contains subscription functionality for XRPL streams.
subscription/types
Package types provides types for the subscription streams, including book changes events.
Package types provides types for the subscription streams, including book changes events.
subscription/v1
Package v1 contains version 1 subscription functionality for XRPL streams.
Package v1 contains version 1 subscription functionality for XRPL streams.
subscription/v1/types
Package types contains data structures for v1 subscription stream types.
Package types contains data structures for v1 subscription stream types.
transactions
Package transactions contains transaction-related queries for XRPL.
Package transactions contains transaction-related queries for XRPL.
transactions/v1
Package v1 contains version 1 transaction queries for XRPL.
Package v1 contains version 1 transaction queries for XRPL.
utility
Package utility provides commands to query XRPL utility methods.
Package utility provides commands to query XRPL utility methods.
utility/v1
Package v1 contains version 1 utility queries for XRPL.
Package v1 contains version 1 utility queries for XRPL.
vault
Package vault contains vault-related queries for XRPL.
Package vault contains vault-related queries for XRPL.
version
Package version defines API versions and version-related utilities for XRPL queries.
Package version defines API versions and version-related utilities for XRPL queries.
rpc
Package rpc provides RPC client functionality for interacting with XRPL servers.
Package rpc provides RPC client functionality for interacting with XRPL servers.
testutil
Package testutil provides utilities for mocking JSON-RPC HTTP clients in tests.
Package testutil provides utilities for mocking JSON-RPC HTTP clients in tests.
types
Package types contains data structures for RPC client configuration and options.
Package types contains data structures for RPC client configuration and options.
Package testutil provides utilities for testing JSON flattening and serialization.
Package testutil provides utilities for testing JSON flattening and serialization.
integration
Package integration provides configuration and utilities for running XRP Ledger integration tests.
Package integration provides configuration and utilities for running XRP Ledger integration tests.
Package time provides time conversion utilities for XRPL timestamps.
Package time provides time conversion utilities for XRPL timestamps.
Package transaction contains XRPL transaction types and related functionality.
Package transaction contains XRPL transaction types and related functionality.
integration
Package integration provides constants and utilities for transaction integration tests.
Package integration provides constants and utilities for transaction integration tests.
types
Package types provides core transaction types and helpers for the XRPL Go library.
Package types provides core transaction types and helpers for the XRPL Go library.
Package wallet provides utilities for deriving and managing XRPL wallets, including keypair generation, address derivation, and offline transaction signing.
Package wallet provides utilities for deriving and managing XRPL wallets, including keypair generation, address derivation, and offline transaction signing.
types
Package types contains data structures for wallet operations and batch signing.
Package types contains data structures for wallet operations and batch signing.
Package websocket provides a client for connecting to an XRPL WebSocket server.
Package websocket provides a client for connecting to an XRPL WebSocket server.
interfaces
Package interfaces defines common interfaces for XRPL WebSocket.
Package interfaces defines common interfaces for XRPL WebSocket.
testutil
Package testutil provides testing utilities for websocket functionality.
Package testutil provides testing utilities for websocket functionality.
types
Package types contains data structures for websocket message types.
Package types contains data structures for websocket message types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL