Asset
This module provides classes and utilities for creating, managing, and interacting with on-chain assets within the MOI framework. It defines three main components:
AssetFactory– Responsible for asset creation.AssetDriver– Provides a driver abstraction for asset logic execution.MAS0AssetLogic– Implements the standard MAS0 asset logic and operations such as mint, burn, and transfer.
AssetFactory
- class AssetFactory()
The
AssetFactoryclass is responsible for creating new assets and deploying their associated custom logic on the MOI network. It defines the staticcreatemethod which constructs anInteractionContextfor asset creation operations.Method Summary
- AssetFactory.static create(signer, symbol, supply, manager, enableEvents, manifest, callsite, calldata)
Creates a new asset creation interaction context.
- Arguments:
signer (Signer) – The signer instance responsible for authorizing the asset creation.
symbol (str) – The symbol or shorthand name of the asset.
supply (int | bigint) – The total maximum supply of the asset.
manager (str) – The manager or owner address (in Hex format).
enableEvents (bool) – Whether to enable event emission for the asset.
manifest (LogicManifest.Manifest) – (Optional) Logic manifest if custom logic is being deployed.
callsite (str) – (Optional) Routine name in the manifest corresponding to the deploy logic.
calldata (list) – (Optional) Additional initialization arguments for the deploy routine.
- Returns:
An
InteractionContextconfigured for asset creation.- Return type:
InteractionContext<OpType.ASSET_CREATE>
Logic
Builds an
AssetCreatePayloadcontaining: -symbol-max_supply-standard(set toAssetStandard.MAS0) -dimension(default 0) -enable_events-manager(converted to Hex) -logic_payloadIf a
manifestis provided: - Searches for a deploy routine matching the givencallsite. - Validates argument counts. - Encodes the manifest and the routine calldata (if applicable).Returns an
InteractionContextinitialized forASSET_CREATE.
Usage Example
const ctx = AssetFactory.create( signer, "GOLD", 1000000n, managerAddress, true, manifest, callsite, 1000, // calldata arg 1 "JOHN" // calldata arg 2 ); const response = await ctx.send();
AssetDriver
- class AssetDriver()
The
AssetDriverclass extendsLogicDriverand represents a driver interface for interacting with a deployed custom asset logic.Constructor
- AssetDriver.constructor(assetId, manifest, signer)
Initializes a new
AssetDriverinstance.- Arguments:
assetId (str) – The unique identifier (asset ID) of the asset.
manifest (LogicManifest.Manifest) – The logic manifest associated with the asset.
signer (Signer) – The signer responsible for authorization.
Logic
The constructor simply calls the base
LogicDriverconstructor with the provided parameters, enabling interaction with the deployed asset logic.Usage Example
const driver = new AssetDriver(assetId, manifest, signer); const response = driver.routines.mint(beneficiary, 5000).send();
MAS0AssetLogic
- class MAS0AssetLogic()
Implements the standard MAS0 asset logic, which provides a set of default routines for asset lifecycle management — including minting, burning, transferring, approving, locking, and querying balances.
Constructor
- MAS0AssetLogic.constructor(assetId, signer)
Initializes a new
MAS0AssetLogicinstance.- Arguments:
assetId (str) – The asset ID to operate on.
signer (Signer) – The signer instance for authorization.
Static Methods
- MAS0AssetLogic.static async newAsset(signer, symbol, supply, manager, enableEvents)
Creates a new MAS0-standard asset on-chain, then returns an instance of
MAS0AssetLogicfor interacting with it.- Returns:
An instance of
MAS0AssetLogic- Return type:
MAS0AssetLogic
Example
const gold = await MAS0AssetLogic.newAsset( signer, "GOLD", 1000000n, managerAddress, true );
- MAS0AssetLogic.static create(signer, symbol, supply, manager, enableEvents)
Builds an
InteractionContextfor creating a MAS0-standard asset.- Returns:
InteractionContext<OpType.ASSET_CREATE>
MAS0 Operations
The following methods correspond to MAS0-standard asset operations.
Each operation returns an InteractionContext, which can be executed by calling .send().
- mint(beneficiary, amount)
Mints new asset units to the specified beneficiary.
- Arguments:
beneficiary (str) – Recipient participant id.
amount (int | bigint) – Amount to mint.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.mint(beneficiary, 5000).send();
- burn(amount)
Burns a specified amount of the asset, reducing total supply.
- Arguments:
amount (int | bigint) – Amount to burn.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.burn(1000).send();
- transfer(beneficiary, amount)
Transfers asset units to another account.
- Arguments:
beneficiary (str) – Recipient participant id.
amount (int | bigint) – Amount to transfer.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.transfer(beneficiary, 2500).send();
- transferFrom(benefactor, beneficiary, amount)
Transfers asset units from a benefactor to a beneficiary (if approved).
- Arguments:
benefactor (str) – The participant id of the original holder.
beneficiary (str) – The receiver participant id.
amount (int | bigint) – Amount to transfer.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.transferFrom(benefactor, beneficiary, 100000).send();
- approve(beneficiary, amount, expiresAt)
Grants spending permission to another account.
- Arguments:
beneficiary (str) – The spender participant id.
amount (int | bigint) – Allowance amount.
expiresAt (int) – Expiration timestamp (UNIX time).
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.approve(beneficiary, 100000, 1765650600).send();
- revoke(beneficiary)
Revokes a previously approved allowance.
- Arguments:
beneficiary (str) – Account to revoke approval from.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.revoke(beneficiary).send();
- lockup(beneficiary, amount)
Locks up a specified amount of tokens under
SARGA_ADDRESS.- Arguments:
beneficiary (str) – Participant id of whose tokens are being locked.
amount (int | bigint) – Amount to lock.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.lockup(beneficiary, 10000).send();
- release(benefactor, beneficiary, amount)
Releases locked-up tokens back to a beneficiary.
- Arguments:
benefactor (str) – The original owner of the locked tokens.
beneficiary (str) – The receiver of the released tokens.
amount (int | bigint) – Amount to release.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const mas0 = new MAS0AssetLogic(assetId, wallet); const response = await mas0.release(benefactor, beneficiary, 100).send();
Readonly Routines
- symbol()
Returns an interaction context for retrieving the asset symbol.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const response = await mas0.symbol().call();
- balanceOf(id)
Retrieves the balance of a given account.
- Arguments:
id (str) – The participant id to query.
- Returns:
InteractionContext<OpType.ASSET_INVOKE>
Example
const balance = await mas0.balanceOf(walletAddress).call();