Stellar PHP SDK API Documentation

AssetTypeCreditAlphanum12 extends AssetTypeCreditAlphanum
in package

Represents an issued asset with a 5-12 character alphanumeric code

AlphaNum12 assets are identified by a longer code (5-12 characters) and the issuer's account ID. These are used for assets with longer names like MYCOIN, TOKENXYZ, etc.

Usage: $token = new AssetTypeCreditAlphanum12("MYTOKEN", "GISSUER..."); // or use the factory method $token = Asset::createNonNativeAsset("MYTOKEN", "GISSUER...");

Tags
see
AssetTypeCreditAlphanum4

For assets with 1-4 character codes

since
1.0.0

Table of Contents

Constants

TYPE_CREDIT_ALPHANUM_12  : mixed = "credit_alphanum12"
TYPE_CREDIT_ALPHANUM_4  : mixed = "credit_alphanum4"
TYPE_NATIVE  : mixed = "native"
TYPE_POOL_SHARE  : mixed = "liquidity_pool_shares"

Properties

$code  : string
$issuer  : string

Methods

__construct()  : mixed
Creates an AlphaNum12 asset with code validation
canonicalForm()  : string
Returns the canonical string representation of an asset
create()  : Asset
Creates an asset from its type, code, and issuer
createFromCanonicalForm()  : Asset|null
Creates an asset from its canonical string representation
createNonNativeAsset()  : AssetTypeCreditAlphanum
Creates a non-native asset with automatic type detection based on code length
fromJson()  : Asset
Creates an asset from JSON data (typically from Horizon responses)
fromXdr()  : Asset
Creates an Asset from its XDR representation
fromXdrChangeTrustAsset()  : Asset
Creates an Asset from its XDR ChangeTrustAsset representation.
fromXdrTrustlineAsset()  : Asset
Creates an Asset from its XDR TrustlineAsset representation.
getCode()  : string
Returns the asset code
getIssuer()  : string
Returns the issuer account ID
getType()  : string
Returns the asset type identifier
native()  : AssetTypeNative
Creates the native XLM asset
setCode()  : void
Sets the asset code
setIssuer()  : void
Sets the issuer account ID
toXdr()  : XdrAsset
Converts this asset to its XDR representation
toXdrChangeTrustAsset()  : XdrChangeTrustAsset
Converts this asset to XDR ChangeTrustAsset format
toXdrTrustlineAsset()  : XdrTrustlineAsset
Converts this asset to XDR TrustlineAsset format

Constants

TYPE_CREDIT_ALPHANUM_12

public mixed TYPE_CREDIT_ALPHANUM_12 = "credit_alphanum12"

TYPE_CREDIT_ALPHANUM_4

public mixed TYPE_CREDIT_ALPHANUM_4 = "credit_alphanum4"

TYPE_NATIVE

public mixed TYPE_NATIVE = "native"

TYPE_POOL_SHARE

public mixed TYPE_POOL_SHARE = "liquidity_pool_shares"

Properties

Methods

__construct()

Creates an AlphaNum12 asset with code validation

public __construct(string $code, string $issuer) : mixed
Parameters
$code : string

Asset code (5-12 characters)

$issuer : string

Issuer account ID (public key starting with G)

Tags
throws
RuntimeException

If the code length is invalid

canonicalForm()

Returns the canonical string representation of an asset

public static canonicalForm(Asset $asset) : string

Format:

  • Native: "native"
  • Issued: "CODE:ISSUER" (e.g., "USD:GABC...")
Parameters
$asset : Asset

The asset to convert

Tags
throws
RuntimeException

If the asset type is unsupported

Return values
string —

The canonical form

create()

Creates an asset from its type, code, and issuer

public static create(string $type[, string|null $code = null ][, string|null $issuer = null ]) : Asset

Pool share assets cannot be created here because they are composed of two assets rather than a code and issuer; construct an AssetTypePoolShare directly.

Parameters
$type : string

TYPE_NATIVE, TYPE_CREDIT_ALPHANUM_4 or TYPE_CREDIT_ALPHANUM_12

$code : string|null = null

Asset code (required for non-native assets)

$issuer : string|null = null

Issuer account ID (required for non-native assets)

Tags
throws
RuntimeException

If parameters are invalid or type is unsupported

see
AssetTypePoolShare

For liquidity pool share assets

Return values
Asset —

The created asset

createFromCanonicalForm()

Creates an asset from its canonical string representation

public static createFromCanonicalForm(string $canonicalForm) : Asset|null

Accepted formats:

  • "native" or "XLM" for native XLM
  • "CODE:ISSUER" for issued assets (e.g., "USD:GABC...")
Parameters
$canonicalForm : string

The canonical asset string

Return values
Asset|null —

The created asset, or null if the format is invalid

createNonNativeAsset()

Creates a non-native asset with automatic type detection based on code length

public static createNonNativeAsset(string $code, string $issuer) : AssetTypeCreditAlphanum

The asset type (AlphaNum4 or AlphaNum12) is determined automatically based on the length of the asset code.

Parameters
$code : string

Asset code (1-12 characters)

$issuer : string

Issuer account ID (public key starting with G)

Tags
throws
RuntimeException

If the code length is invalid

Return values
AssetTypeCreditAlphanum —

The created asset (AlphaNum4 or AlphaNum12)

fromJson()

Creates an asset from JSON data (typically from Horizon responses)

public static fromJson(array<string|int, mixed> $json) : Asset
Parameters
$json : array<string|int, mixed>

JSON data with asset_type, asset_code, and asset_issuer fields

Return values
Asset —

The created asset

fromXdr()

Creates an Asset from its XDR representation

public static fromXdr(XdrAsset $xdrAsset) : Asset
Parameters
$xdrAsset : XdrAsset

The XDR asset data

Tags
throws
InvalidArgumentException

If the asset type is unknown

Return values
Asset —

The reconstructed asset

fromXdrChangeTrustAsset()

Creates an Asset from its XDR ChangeTrustAsset representation.

public static fromXdrChangeTrustAsset(XdrChangeTrustAsset $xdrAsset) : Asset

Handles all asset types including POOL_SHARE.

Parameters
$xdrAsset : XdrChangeTrustAsset

The XDR change trust asset data

Tags
throws
InvalidArgumentException

If the asset type is unknown

Return values
Asset —

The reconstructed asset

fromXdrTrustlineAsset()

Creates an Asset from its XDR TrustlineAsset representation.

public static fromXdrTrustlineAsset(XdrTrustlineAsset $xdrAsset) : Asset

Handles NATIVE, CREDIT_ALPHANUM4, and CREDIT_ALPHANUM12. POOL_SHARE trustline assets contain only a pool ID hash and cannot be reconstructed into an AssetTypePoolShare (which requires both reserve assets).

Parameters
$xdrAsset : XdrTrustlineAsset

The XDR trustline asset data

Tags
throws
InvalidArgumentException

If the asset type is POOL_SHARE or unknown

Return values
Asset —

The reconstructed asset

getCode()

Returns the asset code

public getCode() : string
Return values
string —

The asset code (e.g., "USD", "BTC")

getIssuer()

Returns the issuer account ID

public getIssuer() : string
Return values
string —

The issuer's public key (G...)

getType()

Returns the asset type identifier

public getType() : string
Return values
string —

Always returns "credit_alphanum12"

setCode()

Sets the asset code

public setCode(string $code) : void
Parameters
$code : string

The new asset code

setIssuer()

Sets the issuer account ID

public setIssuer(string $issuer) : void
Parameters
$issuer : string

The new issuer account ID

On this page

Search results