Skip to main content

Asset

An asset is an object that represents a resource on the blockchain. Assets can be used to represent tokens, nfts, etc.

Abstract Asset

The Asset class is an abstract class that cannot be instantiated directly. To create an asset you must use one of the classes that extend Asset.

Asset Type

The type of the asset is defined in the type property of the asset's primitive object. The types of assets available are:

  • AssetType.NFT
  • AssetType.ERC20
  • AssetType.ERC1155

Properties

PropertyTypeDescription
assetIdIDUnique identifier of the asset.
addressEthereumAddressAsset contract address.
amountAmountAmount of the asset.
chainIdChainIdIdentifier of the blockchain in which the asset is located.
metadataMetadataAsset metadata.

Methods

MethodReturnDescription
setAssetId(assetId: ID)voidSets the asset identifier.
setAmount(amount: Amount)voidSets the amount of the asset.
getTransactionHash()TransactionHashGets the hash of the transaction that created the asset.
setTransactionHash(transactionHash: TransactionHash)voidSets the hash of the transaction that created the asset.
getOwner()OwnerGets the address of the owner of the asset.
setOwner(owner: Owner)voidSets the address of the owner of the asset.
equals(other: Asset)booleanCompare if the asset is equal to another asset.
toPrimitive()Primitives<Asset>Gets the primitive representation of the asset.
isSameAddressAccount(address: EthereumAddress)booleanCheck if the account address is the same as the asset address.
isOwned()booleanCheck if the asset has an owner.
isOwnedBy(other: Owner)booleanCompare if the asset is owned by the address of the account.
formatAmount(fixed:number)AmountFormat the amount of the asset.
isNFT()booleanCheck if the asset is an NFT.
isERC20()booleanCheck if the asset is an ERC20.
isERC1155()booleanCheck if the asset is an ERC1155.
decimals()DecimalGets the number of decimal places in the asset.

The NFT class, Token and TokenNft extend from the Asset class. And they represent the different types of assets that can be created.

Minable Assets

The mineable assets are shown in the diagram. They include a prepare method that allows preparing the asset to be mined.

Asset Factory

The AssetsFactory class allows you to create assets. It will create them depending on the type of asset being sent.

import { AssetsFactory, Asset, Primitives } from '@alfabc/sdk';

const primitiveAsset: Primitives<Asset> = {
type: AssetType.NFT,
address: '0x7C6ac312c08b975a0e74Be8Cd8C6ad8b8b4A8DEB', // Contract address
chainId: 80001,
metadata: {
name: 'My NFT',
description: 'Description of my nft',
attributes: [
{
trait_type: 'Color',
value: 'green'
},
{
trait_type: 'Year',
value: '1952'
}
], // An array with the asset's attributes
}
}

const asset = AssetsFactory.from(primitiveAsset); // Create an NFT asset
Valuable objectDescription
OwnerRepresents the address of an account and the owner of an asset. Extends from EthereumAddress