MuxedContract
in package
A contract, optionally paired with a 64-bit multiplexing id (CAP-0084).
With an id the pair renders as a muxed contract address, a "W..." strkey whose payload is the 32-byte contract id followed by the big-endian id (SEP-23). Without an id it renders as the contract address ("C..."). A muxed contract address can receive a Stellar Asset Contract transfer; it is never a Soroban auth address.
Ids above PHP_INT_MAX are held as negative ints, the two's complement form the SDK's uint64 XDR fields use.
Usage:
$muxed = new MuxedContract("CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE", 123456);
// WA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAAAAAAAAAPCIA6IG
$address = $muxed->getAddress();
$parsed = MuxedContract::fromAddress($address); $parsed->getContractId(); // "CA3D5KRY..." $parsed->getId(); // 123456
Tags
Table of Contents
Methods
- __construct() : mixed
- Pairs a contract with a multiplexing id.
- fromAddress() : MuxedContract
- Creates a MuxedContract from a contract address ("C...", no id) or a muxed contract address ("W...").
- fromXdrSCAddress() : MuxedContract
- Creates a MuxedContract from the contract or the muxed contract arm of an SCAddress.
- getAddress() : string
- Returns the muxed contract address ("W...") when an id is set, else the contract address ("C...").
- getContractId() : string
- Returns the contract address.
- getId() : int|null
- Returns the multiplexing id.
- toAddress() : Address
- Converts this object to a Soroban Address: of type Address::TYPE_MUXED_CONTRACT when an id is set, else of type Address::TYPE_CONTRACT.
- toXdrSCAddress() : XdrSCAddress
- Converts this object to an SCAddress: the muxed contract arm when an id is set, else the contract arm.
Methods
__construct()
Pairs a contract with a multiplexing id.
public
__construct(string $contractId[, int|null $id = null ]) : mixed
Parameters
- $contractId : string
-
the contract as a "C..." strkey or as its 32-byte hash in hexadecimal
- $id : int|null = null
-
the multiplexing id; null for the contract on its own. 0 is a valid id.
Tags
fromAddress()
Creates a MuxedContract from a contract address ("C...", no id) or a muxed contract address ("W...").
public
static fromAddress(string $address) : MuxedContract
Parameters
- $address : string
-
the "C..." or "W..." strkey
Tags
Return values
MuxedContract —the decoded contract and id
fromXdrSCAddress()
Creates a MuxedContract from the contract or the muxed contract arm of an SCAddress.
public
static fromXdrSCAddress(XdrSCAddress $address) : MuxedContract
Parameters
- $address : XdrSCAddress
-
the XDR address
Tags
Return values
MuxedContract —the contract, with the id of the muxed contract arm
getAddress()
Returns the muxed contract address ("W...") when an id is set, else the contract address ("C...").
public
getAddress() : string
Return values
string —the strkey of this address
getContractId()
Returns the contract address.
public
getContractId() : string
Return values
string —the "C..." strkey of the contract
getId()
Returns the multiplexing id.
public
getId() : int|null
Return values
int|null —the id, or null for the contract on its own
toAddress()
Converts this object to a Soroban Address: of type Address::TYPE_MUXED_CONTRACT when an id is set, else of type Address::TYPE_CONTRACT.
public
toAddress() : Address
Return values
Address —the Soroban address
toXdrSCAddress()
Converts this object to an SCAddress: the muxed contract arm when an id is set, else the contract arm.
public
toXdrSCAddress() : XdrSCAddress
Return values
XdrSCAddress —the XDR address