Asset

sealed class Asset : Comparable<Asset>

Base Asset class representing assets on the Stellar network.

Assets are the units that are traded on the Stellar network. An asset consists of a type, code, and issuer (except for the native asset, Lumens).

There are three types of assets:

  • Native: The native asset of the Stellar network (Lumens/XLM)

  • AlphaNum4: Issued assets with codes 1-4 characters long

  • AlphaNum12: Issued assets with codes 5-12 characters long

Usage Examples

Native Asset (Lumens)

val xlm = AssetTypeNative

Create Issued Asset

// Automatically detects AlphaNum4 vs AlphaNum12
val usd = Asset.createNonNativeAsset("USD", "GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX")

// Explicit types
val usdc = AssetTypeCreditAlphaNum4("USDC", "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN")
val longName = AssetTypeCreditAlphaNum12("LONGERNAME", "GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX")

Parse from String

val native = Asset.create("native")
val usd = Asset.create("USD:GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX")

XDR Conversion

val asset = Asset.createNonNativeAsset("USD", issuer)
val xdr = asset.toXdr()
val restored = Asset.fromXdr(xdr)

Comparison and Sorting

Assets implement Comparable and are ordered by:

  1. Type (native < alphanum4 < alphanum12)

  2. Code (alphabetically)

  3. Issuer (alphabetically)

See also

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val type: AssetTypeXdr

Returns the asset type.

Functions

Link copied to clipboard
abstract operator fun compareTo(other: Asset): Int
Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean
Link copied to clipboard
suspend fun getContractId(network: Network): String

Returns the contract ID for this asset on the given network.

Link copied to clipboard
abstract override fun hashCode(): Int
Link copied to clipboard
abstract override fun toString(): String

Returns a canonical string representation of this asset.

Link copied to clipboard
abstract fun toXdr(): AssetXdr

Converts this asset to its XDR representation.