Stellar PHP SDK API Documentation

Address

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
see
https://developers.stellar.org

Stellar developer docs Soroban Authorization

since
1.0.0

Table of Contents

Constants

TYPE_ACCOUNT  = 0
TYPE_CLAIMABLE_BALANCE  = 3
TYPE_CONTRACT  = 1
TYPE_LIQUIDITY_POOL  = 4
TYPE_MUXED_ACCOUNT  = 2

Properties

$accountId  : string|null
$claimableBalanceId  : string|null
$contractId  : string|null
$liquidityPoolId  : string|null
$muxedAccountId  : string|null
$type  : int

Methods

__construct()  : mixed
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)

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.

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

hex representation. If you have a str key claimable balance id, you can decode it to hex with StrKey::decodeClaimableBalanceIdHex($claimableBalanceId)

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

hex representation. If you have a str key contract id, you can decode it to hex with StrKey::decodeContractIdHex($contractId)

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

hex representation. If you have a str key liquidity pool id, you can decode it to hex with StrKey::decodeLiquidityPoolIdHex($liquidityPoolId)

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
Parameters
$xdrAddress : XdrSCAddress

the xdr object to create the Address object from.

Tags
throws
RuntimeException

if the XDR address type is unknown or unsupported

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
throws
RuntimeException

if the given XdrSCVal is not of type address

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
throws
Exception

if the address cannot be converted to StrKey format

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
throws
RuntimeException

if the address type is unknown or if required ID fields are null

Return values
XdrSCAddress

the XDR representation of this address

toXdrSCVal()

Converts this object to a XdrSCVal object.

public toXdrSCVal() : XdrSCVal
Tags
throws
RuntimeException

if the address cannot be converted to XDR format

Return values
XdrSCVal

the XdrSCVal representation wrapping this address


        
On this page

Search results