MuxedAccount
in package
Represents a multiplexed Stellar account
Multiplexed accounts (also known as muxed accounts) allow multiple virtual accounts to share a single Stellar account. This is useful for exchanges, payment processors, and other services that need to differentiate between multiple users or sub-accounts while using the same underlying Stellar account.
A muxed account consists of:
- The underlying Ed25519 account ID (G-address)
- An optional 64-bit ID that differentiates virtual accounts
When the ID is present, the account is encoded as an M-address. When absent, it's a regular G-address.
Usage:
// Create a regular account (no ID)
$muxed = new MuxedAccount("GABC...");
// Create a multiplexed account with ID $muxed = new MuxedAccount("GABC...", 12345);
// Get the account ID (M-address if ID present, G-address otherwise) $accountId = $muxed->getAccountId();
// Parse from account ID string $muxed = MuxedAccount::fromAccountId("MABC...");
Tags
Table of Contents
Methods
- __construct() : mixed
- Constructs a new MuxedAccount instance
- fromAccountId() : MuxedAccount
- Creates a MuxedAccount from an account ID string
- fromMed25519AccountId() : MuxedAccount
- Creates a MuxedAccount from a MED25519 account ID (M-address)
- fromXdr() : MuxedAccount
- Creates a MuxedAccount from XDR format
- getAccountId() : string
- Gets the account ID as a string
- getEd25519AccountId() : string
- Gets the underlying Ed25519 account ID
- getId() : int|null
- Gets the muxed account ID
- getXdr() : XdrMuxedAccount
- Gets the XDR representation of the muxed account
- toXdr() : XdrMuxedAccount
- Converts the muxed account to XDR format
Methods
__construct()
Constructs a new MuxedAccount instance
public
__construct(string $ed25519AccountId[, int|null $id = null ]) : mixed
Parameters
- $ed25519AccountId : string
-
The Ed25519 account ID (G-address)
- $id : int|null = null
-
Optional 64-bit ID for multiplexing (creates M-address when set)
Tags
fromAccountId()
Creates a MuxedAccount from an account ID string
public
static fromAccountId(string $accountId) : MuxedAccount
Accepts both G-addresses (regular accounts) and M-addresses (multiplexed accounts).
Parameters
- $accountId : string
-
The account ID (G-address or M-address)
Tags
Return values
MuxedAccount —The created MuxedAccount instance
fromMed25519AccountId()
Creates a MuxedAccount from a MED25519 account ID (M-address)
public
static fromMed25519AccountId(string $med25519AccountId) : MuxedAccount
Parameters
- $med25519AccountId : string
-
The M-address to decode
Return values
MuxedAccount —The created MuxedAccount instance
fromXdr()
Creates a MuxedAccount from XDR format
public
static fromXdr(XdrMuxedAccount $muxedAccount) : MuxedAccount
Parameters
- $muxedAccount : XdrMuxedAccount
-
The XDR muxed account
Tags
Return values
MuxedAccount —The created MuxedAccount instance
getAccountId()
Gets the account ID as a string
public
getAccountId() : string
Returns an M-address if the account has a muxed ID, otherwise returns the underlying G-address.
Return values
string —The account ID (M-address or G-address)
getEd25519AccountId()
Gets the underlying Ed25519 account ID
public
getEd25519AccountId() : string
Return values
string —The Ed25519 account ID (G-address)
getId()
Gets the muxed account ID
public
getId() : int|null
Return values
int|null —The 64-bit ID, or null if not a multiplexed account
getXdr()
Gets the XDR representation of the muxed account
public
getXdr() : XdrMuxedAccount
Return values
XdrMuxedAccount —The XDR muxed account
toXdr()
Converts the muxed account to XDR format
public
toXdr() : XdrMuxedAccount
Return values
XdrMuxedAccount —The XDR representation