Core
Modular
MultiAsset
Abstract Multi Asset

AbstractMultiAsset

RMRK team

AbstractMultiAsset

Abstract Smart contract implementing most of the common logic for contracts implementing IERC5773

Methods

acceptAsset

function acceptAsset(uint256 tokenId, uint256 index, uint64 assetId) external nonpayable

Accepts an asset at from the pending array of given token.

Migrates the asset from the token's pending asset array to the token's active asset array.Active assets cannot be removed by anyone, but can be replaced by a new asset.Requirements: - The caller must own the token or be approved to manage the token's assets - tokenId must exist. - index must be in range of the length of the pending asset array.Emits an {AssetAccepted} event.

Parameters

NameTypeDescription
tokenIduint256ID of the token for which to accept the pending asset
indexuint256Index of the asset in the pending array to accept
assetIduint64ID of the asset expected to be in the index

approveForAssets

function approveForAssets(address to, uint256 tokenId) external nonpayable

Used to grant permission to the user to manage token's assets.

This differs from transfer approvals, as approvals are not cleared when the approved party accepts or rejects an asset, or sets asset priorities. This approval is cleared on token transfer.Only a single account can be approved at a time, so approving the 0x0 address clears previous approvals.Requirements: - The caller must own the token or be an approved operator. - tokenId must exist.Emits an {ApprovalForAssets} event.

Parameters

NameTypeDescription
toaddressAddress of the account to grant the approval to
tokenIduint256ID of the token for which the approval to manage the assets is granted

getActiveAssetPriorities

function getActiveAssetPriorities(uint256 tokenId) external view returns (uint64[] priorities)

Used to retrieve the priorities of the active resoources of a given token.

Asset priorities are a non-sequential array of uint64 values with an array size equal to active asset priorites.

Parameters

NameTypeDescription
tokenIduint256ID of the token for which to retrieve the priorities of the active assets

Returns

NameTypeDescription
prioritiesuint64[]An array of priorities of the active assets of the given token

getActiveAssets

function getActiveAssets(uint256 tokenId) external view returns (uint64[] assetIds)

Used to retrieve IDs of the active assets of given token.

Asset data is stored by reference, in order to access the data corresponding to the ID, call getAssetMetadata(tokenId, assetId).You can safely get 10k

Parameters

NameTypeDescription
tokenIduint256ID of the token to retrieve the IDs of the active assets

Returns

NameTypeDescription
assetIdsuint64[]An array of active asset IDs of the given token

getApprovedForAssets

function getApprovedForAssets(uint256 tokenId) external view returns (address approved)

Used to retrieve the address of the account approved to manage assets of a given token.

Requirements: - tokenId must exist.

Parameters

NameTypeDescription
tokenIduint256ID of the token for which to retrieve the approved address

Returns

NameTypeDescription
approvedaddressAddress of the account that is approved to manage the specified token's assets

getAssetMetadata

function getAssetMetadata(uint256 tokenId, uint64 assetId) external view returns (string metadata)

Used to fetch the asset metadata of the specified token's active asset with the given index.

Assets are stored by reference mapping _assets[assetId].Can be overriden to implement enumerate, fallback or other custom logic.

Parameters

NameTypeDescription
tokenIduint256ID of the token from which to retrieve the asset metadata
assetIduint64Asset Id, must be in the active assets array

Returns

NameTypeDescription
metadatastringThe metadata of the asset belonging to the specified index in the token's active assets array

getAssetReplacements

function getAssetReplacements(uint256 tokenId, uint64 newAssetId) external view returns (uint64 replacesAssetId)

Used to retrieve the asset that will be replaced if a given asset from the token's pending array is accepted.

Asset data is stored by reference, in order to access the data corresponding to the ID, call getAssetMetadata(tokenId, assetId).

Parameters

NameTypeDescription
tokenIduint256ID of the token to check
newAssetIduint64ID of the pending asset which will be accepted

Returns

NameTypeDescription
replacesAssetIduint64ID of the asset which will be replaced

getPendingAssets

function getPendingAssets(uint256 tokenId) external view returns (uint64[] assetIds)

Used to retrieve IDs of the pending assets of given token.

Asset data is stored by reference, in order to access the data corresponding to the ID, call getAssetMetadata(tokenId, assetId).

Parameters

NameTypeDescription
tokenIduint256ID of the token to retrieve the IDs of the pending assets

Returns

NameTypeDescription
assetIdsuint64[]An array of pending asset IDs of the given token

isApprovedForAllForAssets

function isApprovedForAllForAssets(address owner, address operator) external view returns (bool isApproved)

Used to check whether the address has been granted the operator role by a given address or not.

See {setApprovalForAllForAssets}.

Parameters

NameTypeDescription
owneraddressAddress of the account that we are checking for whether it has granted the operator role
operatoraddressAddress of the account that we are checking whether it has the operator role or not

Returns

NameTypeDescription
isApprovedboolA boolean value indicating whether the account we are checking has been granted the operator role

rejectAllAssets

function rejectAllAssets(uint256 tokenId, uint256 maxRejections) external nonpayable

Rejects all assets from the pending array of a given token.

Effecitvely deletes the pending array.Requirements: - The caller must own the token or be approved to manage the token's assets - tokenId must exist.Emits a {AssetRejected} event with assetId = 0.

Parameters

NameTypeDescription
tokenIduint256ID of the token of which to clear the pending array.
maxRejectionsuint256Maximum number of expected assets to reject, used to prevent from rejecting assets which arrive just before this operation.

rejectAsset

function rejectAsset(uint256 tokenId, uint256 index, uint64 assetId) external nonpayable

Rejects an asset from the pending array of given token.

Removes the asset from the token's pending asset array.Requirements: - The caller must own the token or be approved to manage the token's assets - tokenId must exist. - index must be in range of the length of the pending asset array.Emits a {AssetRejected} event.

Parameters

NameTypeDescription
tokenIduint256ID of the token that the asset is being rejected from
indexuint256Index of the asset in the pending array to be rejected
assetIduint64ID of the asset expected to be in the index

setApprovalForAllForAssets

function setApprovalForAllForAssets(address operator, bool approved) external nonpayable

Used to add or remove an operator of assets for the caller.

Operators can call {acceptAsset}, {rejectAsset}, {rejectAllAssets} or {setPriority} for any token owned by the caller.Requirements: - The operator cannot be the caller.Emits an {ApprovalForAllForAssets} event.

Parameters

NameTypeDescription
operatoraddressAddress of the account to which the operator role is granted or revoked from
approvedboolThe boolean value indicating whether the operator role is being granted (true) or revoked (false)

setPriority

function setPriority(uint256 tokenId, uint64[] priorities) external nonpayable

Sets a new priority array for a given token.

The priority array is a non-sequential list of uint64s, where the lowest value is considered highest priority.Value 0 of a priority is a special case equivalent to unitialized.Requirements: - The caller must own the token or be approved to manage the token's assets - tokenId must exist. - The length of priorities must be equal the length of the active assets array.Emits a {AssetPrioritySet} event.

Parameters

NameTypeDescription
tokenIduint256ID of the token to set the priorities for
prioritiesuint64[]An array of priorities of active assets. The succesion of items in the priorities array matches that of the succesion of items in the active array

supportsInterface

function supportsInterface(bytes4 interfaceId) external view returns (bool)

Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP (opens in a new tab) section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

Parameters

NameTypeDescription
interfaceIdbytes4undefined

Returns

NameTypeDescription
_0boolundefined

Events

ApprovalForAllForAssets

event ApprovalForAllForAssets(address indexed owner, address indexed operator, bool approved)

Used to notify listeners that owner has granted approval to the user to manage assets of all of their tokens.

Parameters

NameTypeDescription
owner indexedaddressAddress of the account that has granted the approval for all assets on all of their tokens
operator indexedaddressAddress of the account that has been granted the approval to manage the token's assets on all of the tokens
approvedboolBoolean value signifying whether the permission has been granted (true) or revoked (false)

ApprovalForAssets

event ApprovalForAssets(address indexed owner, address indexed approved, uint256 indexed tokenId)

Used to notify listeners that owner has granted an approval to the user to manage the assets of a given token.

Approvals must be cleared on transfer

Parameters

NameTypeDescription
owner indexedaddressAddress of the account that has granted the approval for all token's assets
approved indexedaddressAddress of the account that has been granted approval to manage the token's assets
tokenId indexeduint256ID of the token on which the approval was granted

AssetAccepted

event AssetAccepted(uint256 indexed tokenId, uint64 indexed assetId, uint64 indexed replacesId)

Used to notify listeners that an asset object at assetId is accepted by the token and migrated from token's pending assets array to active assets array of the token.

Parameters

NameTypeDescription
tokenId indexeduint256ID of the token that had a new asset accepted
assetId indexeduint64ID of the asset that was accepted
replacesId indexeduint64ID of the asset that was replaced

AssetAddedToTokens

event AssetAddedToTokens(uint256[] tokenIds, uint64 indexed assetId, uint64 indexed replacesId)

Used to notify listeners that an asset object at assetId is added to token's pending asset array.

Parameters

NameTypeDescription
tokenIdsuint256[]An array of token IDs that received a new pending asset
assetId indexeduint64ID of the asset that has been added to the token's pending assets array
replacesId indexeduint64ID of the asset that would be replaced

AssetPrioritySet

event AssetPrioritySet(uint256 indexed tokenId)

Used to notify listeners that token's prioritiy array is reordered.

Parameters

NameTypeDescription
tokenId indexeduint256ID of the token that had the asset priority array updated

AssetRejected

event AssetRejected(uint256 indexed tokenId, uint64 indexed assetId)

Used to notify listeners that an asset object at assetId is rejected from token and is dropped from the pending assets array of the token.

Parameters

NameTypeDescription
tokenId indexeduint256ID of the token that had an asset rejected
assetId indexeduint64ID of the asset that was rejected

AssetSet

event AssetSet(uint64 indexed assetId)

Used to notify listeners that an asset object is initialized at assetId.

Parameters

NameTypeDescription
assetId indexeduint64ID of the asset that was initialized

Errors

RMRKApprovalForAssetsToCurrentOwner

error RMRKApprovalForAssetsToCurrentOwner()

Attempting to grant approval of assets to their current owner

RMRKTokenDoesNotHaveAsset

error RMRKTokenDoesNotHaveAsset()

Attempting to compose a NFT of a token without active assets