Core
Other
Extension
Multi Asset Auto Index
Multi Asset Auto Index

RMRKMultiAssetAutoIndex

RMRK team

RMRKMultiAssetAutoIndex

Smart contract of the RMRK MultiAsset AutoIndex module.

Methods

RMRK_INTERFACE

function RMRK_INTERFACE() external pure returns (bytes4 rmrkInterface)

Interface identifier of the @rmrk-team/evm-contracts package

Returns

NameTypeDescription
rmrkInterfacebytes4Interface identifier for implementations of the @rmrk-team/evm-contracts package

VERSION

function VERSION() external pure returns (string version)

Version of the @rmrk-team/evm-contracts package

Returns

NameTypeDescription
versionstringVersion identifier for implementations of the @rmrk-team/evm-contracts package

acceptAsset

function acceptAsset(uint256 tokenId, uint64 assetId) external nonpayable

Accepts an asset from the pending array of given token.

Migrates the asset from the token's pending asset array to the token's active asset array.An active asset 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.Emits an {AssetAccepted} event.

Parameters

NameTypeDescription
tokenIduint256ID of the token for which to accept the pending asset
assetIduint64Id of the pending asset

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

approve

function approve(address to, uint256 tokenId) external nonpayable

Used to grant a one-time approval to manage one's token.

Gives permission to to to transfer tokenId token to another account.The approval is cleared when the token is transferred.Only a single account can be approved at a time, so approving the zero address clears previous approvals.Requirements: - The caller must own the token or be an approved operator. - tokenId must exist.Emits an {Approval} event.

Parameters

NameTypeDescription
toaddressAddress receiving the approval
tokenIduint256ID of the token for which the approval is being granted

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

balanceOf

function balanceOf(address owner) external view returns (uint256 balance)

Used to retrieve the number of tokens in owner's account.

Parameters

NameTypeDescription
owneraddressAddress of the account being checked

Returns

NameTypeDescription
balanceuint256The balance of the given account

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

getApproved

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

Used to retrieve the account approved to manage given token.

Requirements: - tokenId must exist.

Parameters

NameTypeDescription
tokenIduint256ID of the token to check for approval

Returns

NameTypeDescription
approvedaddressAddress of the account approved to manage the 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

isApprovedForAll

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

Used to check if the given address is allowed to manage the tokens of the specified address.

Parameters

NameTypeDescription
owneraddressAddress of the owner of the tokens
operatoraddressAddress being checked for approval

Returns

NameTypeDescription
isApprovedboolA boolean value signifying whether the operator is allowed to manage the tokens of the owner (true) or not (false)

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

ownerOf

function ownerOf(uint256 tokenId) external view returns (address owner)

Used to retrieve the owner of the given token.

Requirements: - tokenId must exist.

Parameters

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

Returns

NameTypeDescription
owneraddressAddress of the account owning the token

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, 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.Emits a {AssetRejected} event.

Parameters

NameTypeDescription
tokenIduint256ID of the token that the asset is being rejected from
assetIduint64Id of the pending asset

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

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId) external nonpayable

Used to safely transfer a given token token from from to to.

Requirements: - from cannot be the zero address. - to cannot be the zero address. - tokenId token must exist and be owned by from. - If the caller is not from, it must be approved to move this token by either {approve} or {setApprovalForAll}. - If to refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.Emits a {Transfer} event.

Parameters

NameTypeDescription
fromaddressAddress to transfer the tokens from
toaddressAddress to transfer the tokens to
tokenIduint256ID of the token to transfer

safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) external nonpayable

Used to safely transfer a given token token from from to to.

Requirements: - from cannot be the zero address. - to cannot be the zero address. - tokenId token must exist and be owned by from. - If the caller is not from, it must be approved to move this token by either {approve} or {setApprovalForAll}. - If to refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.Emits a {Transfer} event.

Parameters

NameTypeDescription
fromaddressAddress to transfer the tokens from
toaddressAddress to transfer the tokens to
tokenIduint256ID of the token to transfer
databytesAdditional data without a specified format to be sent along with the token transaction

setApprovalForAll

function setApprovalForAll(address operator, bool approved) external nonpayable

Used to approve or remove operator as an operator for the caller.

Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.Requirements: - The operator cannot be the caller.Emits an {ApprovalForAll} event.

Parameters

NameTypeDescription
operatoraddressAddress of the operator being managed
approvedboolA boolean value signifying whether the approval is being granted (true) or (revoked)

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

transferFrom

function transferFrom(address from, address to, uint256 tokenId) external nonpayable

Transfers a given token from from to to.

Requirements: - from cannot be the zero address. - to cannot be the zero address. - tokenId token must be owned by from. - If the caller is not from, it must be approved to move this token by either {approve} or {setApprovalForAll}.Emits a {Transfer} event.

Parameters

NameTypeDescription
fromaddressAddress from which to transfer the token from
toaddressAddress to which to transfer the token to
tokenIduint256ID of the token to transfer

Events

Approval

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

Emitted when owner enables approved to manage the tokenId token.

Parameters

NameTypeDescription
owner indexedaddressundefined
approved indexedaddressundefined
tokenId indexeduint256undefined

ApprovalForAll

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

Emitted when owner enables or disables (approved) operator to manage all of its assets.

Parameters

NameTypeDescription
owner indexedaddressundefined
operator indexedaddressundefined
approvedboolundefined

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

Transfer

event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)

Emitted when tokenId token is transferred from from to to.

Parameters

NameTypeDescription
from indexedaddressundefined
to indexedaddressundefined
tokenId indexeduint256undefined

Errors

ERC721AddressZeroIsNotaValidOwner

error ERC721AddressZeroIsNotaValidOwner()

Attempting to grant the token to 0x0 address

ERC721ApprovalToCurrentOwner

error ERC721ApprovalToCurrentOwner()

Attempting to grant approval to the current owner of the token

ERC721ApproveCallerIsNotOwnerNorApprovedForAll

error ERC721ApproveCallerIsNotOwnerNorApprovedForAll()

Attempting to grant approval when not being owner or approved for all should not be permitted

ERC721ApproveToCaller

error ERC721ApproveToCaller()

Attempting to grant approval to self

ERC721InvalidTokenId

error ERC721InvalidTokenId()

Attempting to use an invalid token ID

ERC721NotApprovedOrOwner

error ERC721NotApprovedOrOwner()

Attempting to manage a token without being its owner or approved by the owner

ERC721TransferFromIncorrectOwner

error ERC721TransferFromIncorrectOwner()

Attempting to transfer the token from an address that is not the owner

ERC721TransferToNonReceiverImplementer

error ERC721TransferToNonReceiverImplementer()

Attempting to safe transfer to an address that is unable to receive the token

ERC721TransferToTheZeroAddress

error ERC721TransferToTheZeroAddress()

Attempting to transfer the token to a 0x0 address

IndexOutOfBounds

error IndexOutOfBounds()

RMRKApprovalForAssetsToCurrentOwner

error RMRKApprovalForAssetsToCurrentOwner()

Attempting to grant approval of assets to their current owner

RMRKApproveForAssetsCallerIsNotOwnerNorApprovedForAll

error RMRKApproveForAssetsCallerIsNotOwnerNorApprovedForAll()

Attempting to grant approval of assets without being the caller or approved for all

RMRKBadPriorityListLength

error RMRKBadPriorityListLength()

Attempting to set the priorities with an array of length that doesn't match the length of active assets array

RMRKIndexOutOfRange

error RMRKIndexOutOfRange()

Attempting to interact with an asset, using index greater than number of assets

RMRKNotApprovedForAssetsOrOwner

error RMRKNotApprovedForAssetsOrOwner()

Attempting to manage an asset without owning it or having been granted permission by the owner to do so

RMRKTokenDoesNotHaveAsset

error RMRKTokenDoesNotHaveAsset()

Attempting to compose a NFT of a token without active assets

RMRKUnexpectedAssetId

error RMRKUnexpectedAssetId()

Attempting to accept or reject an asset which does not match the one at the specified index

RMRKUnexpectedNumberOfAssets

error RMRKUnexpectedNumberOfAssets()

Attempting to reject all pending assets but more assets than expected are pending