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 = AssetTypeNativeContent copied to clipboard
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")Content copied to clipboard
Parse from String
val native = Asset.create("native")
val usd = Asset.create("USD:GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX")Content copied to clipboard
XDR Conversion
val asset = Asset.createNonNativeAsset("USD", issuer)
val xdr = asset.toXdr()
val restored = Asset.fromXdr(xdr)Content copied to clipboard
Comparison and Sorting
Assets implement Comparable and are ordered by:
Type (native < alphanum4 < alphanum12)
Code (alphabetically)
Issuer (alphabetically)