Asset

public class Asset : @unchecked Sendable

Base Asset class. See Stellar developer docs

  • The type of asset (native, alphanum4, alphanum12, or pool share).

    Declaration

    Swift

    public let type: Int32
  • The asset code (e.g., “USD”, “BTC”). Nil for native assets.

    Declaration

    Swift

    public let code: String?
  • The issuer keypair for this asset. Nil for native assets.

    Declaration

    Swift

    public let issuer: KeyPair?
  • Creates an Asset object based on the given type, code and issuer. Assets can have the types: native, alphanumeric 4, alphanumeric 12. The asset of type native has no code and no issuer. Assets of type alphanumeric 4, alphanumeric 12 must have a code and an issuer.

    Declaration

    Swift

    public init?(type: Int32, code: String? = nil, issuer: KeyPair? = nil)

    Parameters

    type

    Type of asset. Possible values: AssetType.ASSET_TYPE_NATIVE, AssetType.ASSET_TYPE_CREDIT_ALPHANUM4 and AssetType.ASSET_TYPE_CREDIT_ALPHANUM12.

    code

    Code of asset. E.g. “BTC”. Any characters from the set [a-z][A-Z][0-9] are allowed. If the value of the parameter ‘type’ is AssetType.ASSET_TYPE_NATIVE the value of the parameter ‘code’ will be ignored. If ‘type’ has the value AssetType.ASSET_TYPE_CREDIT_ALPHANUM4 then ‘code’ must be not nil and not empty, 4-character maximum. If ‘type’ is AssetType.ASSET_TYPE_CREDIT_ALPHANUM12 then ‘code’ must be not nil and not shorter than 5 characters, 12-character maximum.

    issuer

    Issuer of the asset. If the value of the parameter ‘type’ is AssetType.ASSET_TYPE_NATIVE the value of the parameter issuer will be ignored. If the value of the parameter ‘type’ is NOT AssetType.ASSET_TYPE_NATIVE, the value of issuer must be a not nil.

    Return Value

    an Asset object or nil for invalid parameter values.

  • Creates an Asset from its canonical string representation (e.g., “native” or “USD:GXXX…”).

    Declaration

    Swift

    public convenience init?(canonicalForm: String)
  • Returns the canonical string representation of this asset (e.g., “native” or “USD:GXXX…”).

    Declaration

    Swift

    public func toCanonicalForm() -> String
  • Generates XDR object from the Asset object. Throws StellarSDKError.xdrEncodingError if the XDR Object could not be created.

    Declaration

    Swift

    public func toXDR() throws -> AssetXDR
  • Generates TrustlineAssetXDR object for trustline operations.

    Declaration

    Swift

    public func toTrustlineAssetXDR() throws -> TrustlineAssetXDR
  • Generates Asset object from a given XDR object.

    Throws

    Throws StellarSDKError.xdrDecodingError if the Asset object could not be created from the given.

    Declaration

    Swift

    public static func fromXDR(assetXDR: AssetXDR) throws -> Asset

    Parameters

    assetXDR

    the AssetXDR object to be used create the Asset object.