Address
in package
Soroban address representing accounts, contracts, and other Stellar entities
This class represents addresses used in Soroban smart contracts for authorization and identification. An Address can represent different entity types:
- Account: Regular Stellar accounts (G-prefixed addresses)
- Contract: Deployed smart contracts (C-prefixed addresses)
- Muxed Account: Multiplexed accounts (M-prefixed addresses)
- Claimable Balance: Claimable balance IDs
- Liquidity Pool: AMM liquidity pool IDs
Addresses are used in authorization entries and as contract function arguments.
Tags
Table of Contents
Constants
- TYPE_ACCOUNT : mixed = 0
- TYPE_CLAIMABLE_BALANCE : mixed = 3
- TYPE_CONTRACT : mixed = 1
- TYPE_LIQUIDITY_POOL : mixed = 4
- TYPE_MUXED_ACCOUNT : mixed = 2
Properties
- $accountId : string|null
- $claimableBalanceId : string|null
- $contractId : string|null
- $liquidityPoolId : string|null
- $muxedAccountId : string|null
- $type : int
Methods
- __construct() : mixed
- deriveContractId() : string
- Derives the contract id a deployment by the given deployer with the given salt creates on the given network.
- fromAccountId() : Address
- Creates a new instance of Address from the given account id ("G...")
- fromAnyId() : Address|null
- Tries to convert a given id to an Address. The given id can be a contract id, an account id, a muxed account id, a claimable balance id, or a liquidity pool id.
- fromClaimableBalanceId() : Address
- Creates a new instance of Address from the given claimable balance id.
- fromContractId() : Address
- Creates a new instance of Address from the given contract id.
- fromLiquidityPoolId() : Address
- Creates a new instance of Address from the given liquidity pool id.
- fromMuxedAccountId() : Address
- Creates a new instance of Address from the given muxed account id ("M...")
- fromXdr() : Address
- Creates an Address object from the given XdrSCAddress object.
- fromXdrSCVal() : Address
- Creates an Address object from the given XdrSCVal object.
- getAccountId() : string|null
- Returns the account id if this is an account address.
- getClaimableBalanceId() : string|null
- Returns the claimable balance id if this is a claimable balance address.
- getContractId() : string|null
- Returns the contract id if this is a contract address.
- getLiquidityPoolId() : string|null
- Returns the liquidity pool id if this is a liquidity pool address.
- getMuxedAccountId() : string|null
- Returns the muxed account id if this is a muxed account address.
- getType() : int
- Returns the type of address.
- setAccountId() : void
- Sets the account id.
- setClaimableBalanceId() : void
- Sets the claimable balance id.
- setContractId() : void
- Sets the contract id.
- setLiquidityPoolId() : void
- Sets the liquidity pool id.
- setMuxedAccountId() : void
- Sets the muxed account id.
- setType() : void
- Sets the type of address.
- toStrKey() : string
- Returns the StrKey representation of the address.
- toXdr() : XdrSCAddress
- Converts this object to its XDR representation.
- toXdrSCVal() : XdrSCVal
- Converts this object to a XdrSCVal object.
Constants
TYPE_ACCOUNT
public
mixed
TYPE_ACCOUNT
= 0
TYPE_CLAIMABLE_BALANCE
public
mixed
TYPE_CLAIMABLE_BALANCE
= 3
TYPE_CONTRACT
public
mixed
TYPE_CONTRACT
= 1
TYPE_LIQUIDITY_POOL
public
mixed
TYPE_LIQUIDITY_POOL
= 4
TYPE_MUXED_ACCOUNT
public
mixed
TYPE_MUXED_ACCOUNT
= 2
Properties
$accountId
public
string|null
$accountId
= null
only present if type is TYPE_ACCOUNT (0). ("G...")
$claimableBalanceId
public
string|null
$claimableBalanceId
= null
only present if type is TYPE_CLAIMABLE_BALANCE (3).
$contractId
public
string|null
$contractId
= null
hex representation of the contract id. Only present if type is TYPE_CONTRACT (1). If the StrKey representation is needed ("C..."), it can be encoded with StrKey::encodeContractIdHex($contractId)
$liquidityPoolId
public
string|null
$liquidityPoolId
= null
only present if type is TYPE_LIQUIDITY_POOL (4).
$muxedAccountId
public
string|null
$muxedAccountId
= null
("M...") - only present if type is TYPE_MUXED_ACCOUNT (2).
$type
public
int
$type
type of address. Can be TYPE_ACCOUNT (0), TYPE_CONTRACT (1), TYPE_MUXED_ACCOUNT (2), TYPE_CLAIMABLE_BALANCE (3), TYPE_LIQUIDITY_POOL (4).
Methods
__construct()
public
__construct(int $type[, string|null $accountId = null ][, string|null $contractId = null ][, string|null $muxedAccountId = null ][, string|null $claimableBalanceId = null ][, string|null $liquidityPoolId = null ]) : mixed
Parameters
- $type : int
-
type of address. can be one of TYPE_ACCOUNT (0), TYPE_CONTRACT (1), TYPE_MUXED_ACCOUNT (2), TYPE_CLAIMABLE_BALANCE (3), TYPE_LIQUIDITY_POOL (4).
- $accountId : string|null = null
-
required if type is TYPE_ACCOUNT (0), otherwise null
- $contractId : string|null = null
-
hex representation. Required if type is TYPE_CONTRACT (1).
- $muxedAccountId : string|null = null
-
required if type is TYPE_MUXED_ACCOUNT (2), otherwise null
- $claimableBalanceId : string|null = null
-
required if type is TYPE_CLAIMABLE_BALANCE (3), otherwise null
- $liquidityPoolId : string|null = null
-
required if type is TYPE_LIQUIDITY_POOL (4), otherwise null
If you have a StrKey representation of the contract id ("C..."), you can decode it to hex with StrKey::decodeContractIdHex($contractId)
deriveContractId()
Derives the contract id a deployment by the given deployer with the given salt creates on the given network.
public
static deriveContractId(Address $deployer, string $salt, Network $network) : string
The id depends only on the deployer address, the salt and the network; the executable the contract is created with (wasm hash, CAP-85 external reference or Stellar asset) does not enter the derivation. Use it to know a contract's address before deploying, for example when the address is needed in constructor arguments of another contract.
Parameters
- $deployer : Address
-
the address the deployment is issued from (account or contract)
- $salt : string
-
the 32 byte salt the deployment uses
- $network : Network
-
the network the contract is deployed to
Tags
Return values
string —the derived contract id ("C...")
fromAccountId()
Creates a new instance of Address from the given account id ("G...")
public
static fromAccountId(string $accountId) : Address
Parameters
- $accountId : string
-
the account id to create the Address object from ("G...")
Return values
Address —the created Address object.
fromAnyId()
Tries to convert a given id to an Address. The given id can be a contract id, an account id, a muxed account id, a claimable balance id, or a liquidity pool id.
public
static fromAnyId(string $id) : Address|null
If not, returns null.
A bare 32-byte hash in hexadecimal is not self-describing, so 64 hex characters resolve as a contract id. For a claimable balance, pass the "B..." strkey or the hexadecimal that carries its type discriminant (66 or 72 characters).
Parameters
- $id : string
-
a contract id, an account id, a muxed account id, a claimable balance id, or a liquidity pool id.
Return values
Address|null —The address if could be converted.
fromClaimableBalanceId()
Creates a new instance of Address from the given claimable balance id.
public
static fromClaimableBalanceId(string $claimableBalanceId) : Address
Parameters
- $claimableBalanceId : string
-
the balance id as a "B..." strkey, as the bare balance hash in hexadecimal, or as the hash behind its type discriminant (66 or 72 hexadecimal characters). The created Address reports it in the 72-character form Horizon serves, for every spelling.
Tags
Return values
Address —the created Address object.
fromContractId()
Creates a new instance of Address from the given contract id.
public
static fromContractId(string $contractId) : Address
Parameters
- $contractId : string
-
the contract id as a "C..." strkey or as the contract hash in hexadecimal. The created Address reports it as canonical lower case hexadecimal for either spelling.
Tags
Return values
Address —the created Address object.
fromLiquidityPoolId()
Creates a new instance of Address from the given liquidity pool id.
public
static fromLiquidityPoolId(string $liquidityPoolId) : Address
Parameters
- $liquidityPoolId : string
-
the pool id as an "L..." strkey or as the pool hash in hexadecimal. The created Address reports it as canonical lower case hexadecimal for either spelling.
Tags
Return values
Address —the created Address object.
fromMuxedAccountId()
Creates a new instance of Address from the given muxed account id ("M...")
public
static fromMuxedAccountId(string $muxedAccountId) : Address
Parameters
- $muxedAccountId : string
-
the muxed account id to create the Address object from ("M...")
Return values
Address —the created Address object.
fromXdr()
Creates an Address object from the given XdrSCAddress object.
public
static fromXdr(XdrSCAddress $xdrAddress) : Address
Contract and liquidity pool ids are reported in their canonical hex form, a claimable balance id in the 72-character form Horizon serves - whichever spelling the XDR object was built from.
Parameters
- $xdrAddress : XdrSCAddress
-
the xdr object to create the Address object from.
Tags
Return values
Address —the created Address object.
fromXdrSCVal()
Creates an Address object from the given XdrSCVal object.
public
static fromXdrSCVal(XdrSCVal $val) : Address
Parameters
- $val : XdrSCVal
-
the XdrSCVal to create the Address object from.
Tags
Return values
Address —the created Address object.
getAccountId()
Returns the account id if this is an account address.
public
getAccountId() : string|null
Return values
string|null —the account id (G-prefixed), only present if type is TYPE_ACCOUNT
getClaimableBalanceId()
Returns the claimable balance id if this is a claimable balance address.
public
getClaimableBalanceId() : string|null
Return values
string|null —the claimable balance id as hex, only present if type is TYPE_CLAIMABLE_BALANCE
getContractId()
Returns the contract id if this is a contract address.
public
getContractId() : string|null
Return values
string|null —the contract id as hex, only present if type is TYPE_CONTRACT
getLiquidityPoolId()
Returns the liquidity pool id if this is a liquidity pool address.
public
getLiquidityPoolId() : string|null
Return values
string|null —the liquidity pool id as hex, only present if type is TYPE_LIQUIDITY_POOL
getMuxedAccountId()
Returns the muxed account id if this is a muxed account address.
public
getMuxedAccountId() : string|null
Return values
string|null —the muxed account id (M-prefixed), only present if type is TYPE_MUXED_ACCOUNT
getType()
Returns the type of address.
public
getType() : int
Return values
int —the address type (TYPE_ACCOUNT, TYPE_CONTRACT, TYPE_MUXED_ACCOUNT, TYPE_CLAIMABLE_BALANCE, or TYPE_LIQUIDITY_POOL)
setAccountId()
Sets the account id.
public
setAccountId(string|null $accountId) : void
Parameters
- $accountId : string|null
-
the account id (G-prefixed), only required if type is TYPE_ACCOUNT
setClaimableBalanceId()
Sets the claimable balance id.
public
setClaimableBalanceId(string|null $claimableBalanceId) : void
Parameters
- $claimableBalanceId : string|null
-
the claimable balance id as hex, only required if type is TYPE_CLAIMABLE_BALANCE
setContractId()
Sets the contract id.
public
setContractId(string|null $contractId) : void
Parameters
- $contractId : string|null
-
the contract id as hex, only required if type is TYPE_CONTRACT
setLiquidityPoolId()
Sets the liquidity pool id.
public
setLiquidityPoolId(string|null $liquidityPoolId) : void
Parameters
- $liquidityPoolId : string|null
-
the liquidity pool id as hex, only required if type is TYPE_LIQUIDITY_POOL
setMuxedAccountId()
Sets the muxed account id.
public
setMuxedAccountId(string|null $muxedAccountId) : void
Parameters
- $muxedAccountId : string|null
-
the muxed account id (M-prefixed), only required if type is TYPE_MUXED_ACCOUNT
setType()
Sets the type of address.
public
setType(int $type) : void
Parameters
- $type : int
-
the address type (TYPE_ACCOUNT, TYPE_CONTRACT, TYPE_MUXED_ACCOUNT, TYPE_CLAIMABLE_BALANCE, or TYPE_LIQUIDITY_POOL)
toStrKey()
Returns the StrKey representation of the address.
public
toStrKey() : string
Tags
Return values
string —the StrKey encoded address (e.g., G-prefixed for accounts, C-prefixed for contracts)
toXdr()
Converts this object to its XDR representation.
public
toXdr() : XdrSCAddress
Tags
Return values
XdrSCAddress —the XDR representation of this address
toXdrSCVal()
Converts this object to a XdrSCVal object.
public
toXdrSCVal() : XdrSCVal
Tags
Return values
XdrSCVal —the XdrSCVal representation wrapping this address