Helios API/ API Reference/ Classes/

Assets

Represents a list of non-Ada tokens.

Hierarchy

Index

Constructors

constructor

new Assets(props?)

Note: the assets are normalized by removing entries with 0 tokens, and merging all entries with the same MintingPolicyHash and token name.

Parameters

NameTypeDescription
props?AssetsPropsEither a list of AssetClass/quantity pairs, or a list of MintingPolicyHash/tokens pairs (where each tokens entry is a bytearray/quantity pair).

Overrides

CborData.constructor

Accessors

mintingPolicies

get mintingPolicies(): MintingPolicyHash[]

Returns a list of all the minting policies.

Returns

MintingPolicyHash[]

nTokenTypes

get nTokenTypes(): number

Returns

number

Methods

_toUplcData

_toUplcData(): MapData

Used when generating script contexts for running programs

Returns

MapData

add

add(other): Assets

Parameters

NameType
otherAssets

Returns

Assets

addComponent

addComponent(mph, tokenName, qty): void

Mutates 'this'.

Parameters

Returns

void

addTokens

addTokens(mph, tokens): void

Mutates 'this'. Throws error if mph is already contained in 'this'.

Parameters

Returns

void

allPositive

allPositive(): boolean

Returns

boolean

assertAllPositive

assertAllPositive(): void

Throws an error if any contained quantity <= 0n

Returns

void

assertSorted

assertSorted(): void

Returns

void

dump

dump(): any

Returns

any

eq

eq(other): boolean

Parameters

NameType
otherAssets

Returns

boolean

ge

ge(other): boolean

Parameters

NameType
otherAssets

Returns

boolean

get

get(mph, tokenName): bigint

Parameters

Returns

bigint

getTokenNames

getTokenNames(mph): ByteArray[]

Parameters

Returns

ByteArray[]

getTokens

getTokens(mph): [ByteArray, HInt][]

Returns empty if mph not found

Parameters

NameType
mphMintingPolicyHash

Returns

[ByteArray, HInt][]

gt

gt(other): boolean

Strict gt, if other contains assets this one doesn't contain => return false

Parameters

NameType
otherAssets

Returns

boolean

has

has(mph, tokenName): boolean

Parameters

Returns

boolean

isZero

isZero(): boolean

Returns

boolean

mul

mul(scalar): Assets

Parameters

NameType
scalarHInt | HIntProps

Returns

Assets

normalize

normalize(): void

Removes zeros and merges duplicates. In-place algorithm. Keeps the same order as much as possible.

Returns

void

removeZeroes

removeZeroes(): void

Mutates 'this'

Returns

void

sort

sort(): void

Makes sure minting policies are in correct order, and for each minting policy make sure the tokens are in the correct order Mutates 'this'

Returns

void

sub

sub(other): Assets

Parameters

NameType
otherAssets

Returns

Assets

toCbor

toCbor(): number[]

Returns

number[]

Inherited from

CborData.toCbor

toCborHex

toCborHex(): string

Returns

string

Inherited from

CborData.toCborHex

fromCbor

Static fromCbor(bytes): Assets

Parameters

NameType
bytesnumber[]

Returns

Assets

fromProps

Static fromProps(props): Assets

Parameters

NameType
propsAssets | AssetsProps

Returns

Assets