Skip to main content

LSP8IdentifiableDigitalAsset

The LSP8IdentifiableDigitalAsset contract represents identifiable digital assets (NFTs) that can be uniquely traded and given metadata using the ERC725Y Standard. Each NFT is identified with a tokenId, based on ERC721.

A bytes32 value is used for tokenId to allow many uses of token identification, including numbers, contract addresses, and hashed values (i.e., serial numbers).

note

LSP8IdentifiableDigitalAsset contract also contains the methods from the ERC165 Standard:

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

Public Functions​

constructor​

constructor(
string memory name_,
string memory symbol_,
address newOwner_
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_)

Sets the initial owner of the token, and sets the following data keys on the ERC725Y Data Key-Value Store:

Parameters:​

NameTypeDescription
name_stringThe name of the token.
symbol_stringThe symbol of the token.
newOwner_addressThe owner of the contract.

totalSupply​

function totalSupply() public view returns (uint256 value)

Returns the number of existing tokens of this contract.

Return Values:​

NameTypeDescription
valueuint256The number of existing tokens.

balanceOf​

function balanceOf(address tokenOwner) public view returns (uint256 value)

Returns the number of tokens owned by the tokenOwner address.

Parameters:​

NameTypeDescription
tokenOwneraddressThe address to query.

Return Values:​

NameTypeDescription
valueuint256The number of tokens owned by this address.

tokenOwnerOf​

function tokenOwnerOf(bytes32 tokenId) public view returns (address tokenOwner)

Returns the tokenOwner address of the tokenId.

Parameters:​

NameTypeDescription
tokenIdbytes32The token to query.

Return Values:​

NameTypeDescription
tokenOwneraddressThe token owner.
note

Requirements:​

  • tokenId must exist.

tokenIdsOf​

function tokenIdsOf(address tokenOwner) public view returns (bytes32[] memory tokensId)

Returns the list of tokenIds for the tokenOwner address.

Parameters:​

NameTypeDescription
tokenOwneraddressThe address to query.

Return Values:​

NameTypeDescription
tokensIdbytes32[ ]The list of owned token ids.

authorizeOperator​

function authorizeOperator(
address operator,
bytes32 tokenId
) public

Sets the operator address as an operator of a particular tokenId.

Triggers the AuthorizedOperator event when an address gets authorized as an operator.

Parameters:​

NameTypeDescription
operatoraddressThe address to authorize as an operator.
tokenIdbytes32The token to enable operator status to.
note

Requirements:​

  • tokenId must exist.
  • Caller must be current tokenOwner of tokenId.
  • operator cannot be calling address.
  • operator cannot be the zero address.

revokeOperator​

function revokeOperator(
address operator
bytes32 tokenId
) public

Removes the operator address as an operator of a particular tokenId.

Triggers the RevokedOperator event when an address gets revoked as an operator.

Parameters:​

NameTypeDescription
operatoraddressThe address to revoke as an operator.
tokenIdbytes32The token to disable operator status to.
note

Requirements:​

  • tokenId must exist.
  • Caller must be current tokenOwner of tokenId.
  • operator cannot be calling address.
  • operator cannot be the zero address.

isOperatorFor​

function isOperatorFor(
address operator,
bytes32 tokenId
) public view returns (bool result)

Returns whether the operator address is an operator of the tokenId. Operators can send and burn tokens on behalf of their owners.

note

The tokenOwner is its own operator.

Parameters:​

NameTypeDescription
operatoraddressThe address to query operator status for.
tokenIdbytes32The token to query.

Return Values:​

NameTypeDescription
resultboolTRUE if operator address is an operator for tokenId, false otherwise.
note

Requirements:​

  • tokenId must exist.
  • Caller must be current tokenOwner of tokenId.

getOperatorsOf​

function getOperatorsOf(bytes32 tokenId) public view returns (address[] memory operators)

Returns all operator addresses of a particular tokenId.

Parameters:​

NameTypeDescription
tokenIdbytes32The token to query.

Return Values:​

NameTypeDescription
operatorsaddress[ ]The list of operators.
note

Requirements:​

  • tokenId must exist.

transfer​

function transfer(
address from,
address to,
bytes32 tokenId,
bool force,
bytes memory data
) public

Transfers the token with a particular tokenId from the from address to the to address. The force parameter MUST be set to TRUE when transferring tokens to Externally Owned Accounts (EOAs) or contracts that do not implement the LSP1 - Universal Receiver Delegate standard.

Triggers the Transfer event when the token gets successfully transferred.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
forceboolWhen set to TRUE, to may be any address; when set to FALSE to must be a contract that supports LSP1 UniversalReceiver and not revert.
databytesAdditional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.
note

Requirements:​

  • from cannot be the zero address.
  • to cannot be the zero address.
  • from and to cannot be the same address.
  • tokenId token must be owned by from.
  • If the caller is not from, it must be an operator of tokenId.

transferBatch​

function transferBatch(
address[] from,
address[] to,
bytes32[] tokenId,
bool[] force,
bytes[] memory data
) public

Transfers multiple tokens based on the from, to, and tokenId arrays. If any transfer fails, the whole call will revert.

Triggers the Transfer event when the tokens get successfully transferred.

Parameters:​

NameTypeDescription
fromaddress[]The list of sender addresses.
toaddress[]The list of recipient addresses.
tokenIdbytes32[]The list of tokenIds to transfer.
forcebool[]When set to TRUE, to may be any address; when set to FALSE to must be a contract that supports LSP1 UniversalReceiver and not revert.
databytes[]Additional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.
note

Requirements:​

  • from, to, tokenId lists are the same length.
  • No values in from can be the zero address.
  • No values in to can be the zero address.
  • from and to cannot be the same address at the same index of each lists.
  • Each tokenId token must be owned by from.
  • If the caller is not from, it must be an operator of each tokenId.

Internal Functions​

These internal functions can be extended via override to add some custom logic.

Warning

By deploying an LSP8IdentifiableDigitalAsset contract, there will be no public mint or burn function. In order to use them you have to extend the smart contracts and create custom methods using the internal functions.

_mint​

function _mint(
address to,
bytes32 tokenId,
bool force,
bytes memory data
) internal virtual

Mints tokenId and transfers it to to.

Triggers the Transfer event when tokens get successfully transferred.

Parameters:​

NameTypeDescription
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
forceboolWhen set to TRUE, to may be any address; when set to FALSE to must be a contract that supports LSP1 UniversalReceiver and not revert.
memorybytesAdditional data the caller wants included in the emitted event, and sent in the hook to to address.
note

Requirements:​

  • tokenId must not exist.
  • to cannot be the zero address.

_transfer​

function _transfer(
address from,
address to,
bytes32 tokenId,
bool force,
bytes memory data
) internal virtual

Transfers tokenId from from to to.

Triggers the Transfer event when tokens get successfully transferred.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
forceboolWhen set to TRUE, to may be any address; when set to FALSE to must be a contract that supports LSP1 UniversalReceiver and not revert.
memorybytesAdditional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.
note

Requirements:​

  • to cannot be the zero address.
  • tokenId token must be owned by from.

_burn​

function _burn(
address from,
bytes32 tokenId,
bytes memory data
) internal virtual

Burns tokenId and clear the operators authorized for the tokenId.

Triggers the Transfer event when tokens get successfully transferred.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
tokenIdbytes32The token to burn.
databytesAdditional data the caller wants included in the emitted event, and sent in the hook to from address.
note

Requirements:​

  • from cannot be the zero address.
  • tokenId must exist.

_beforeTokenTransfer​

function _beforeTokenTransfer(
address from,
address to,
bytes32 tokenId
) internal virtual

Hook that is called before any token transfer. This includes minting and burning.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
note

Notice:​

  • When from and to are both non-zero, from's tokenId will be transferred to to.
  • When from is zero, tokenId will be minted for to.
  • When to is zero, from's tokenId will be burned.

_notifyTokenSender​

function _notifyTokenSender(
address from,
address to,
bytes32 tokenId,
bytes memory data
) internal virtual

An attempt is made to notify the token receiver about the tokenId token being received by calling the universalReceiver(...) function on the receiver address if it exists.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
databytesAdditional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.

_notifyTokenReceiver​

function _notifyTokenReceiver(
address from,
address to,
bytes32 tokenId,
bool force,
bytes memory data
) internal virtual

An attempt is made to notify the token receiver about the tokenId token being received by calling the universalReceiver(...) function on the receiver address if it exists.

Parameters:​

NameTypeDescription
fromaddressThe sender address.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
forceboolWhen set to TRUE, to may be any address; when set to FALSE to must be a contract that supports LSP1 UniversalReceiver and not revert.
memorybytesAdditional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.

_revokeOperator​

function _revokeOperator(
address operator,
address tokenOwner,
bytes32 tokenId
) internal virtual

Revoke the operator of the tokenId token which belongs to tokenOwner.

Parameters:​

NameTypeDescription
operatoraddressThe address of the operator to revoke.
tokenOwneraddressThe address that is the owner of tokenId.
tokenIdbytes32The token to disable operator status to.

_clearOperators​

function clearOperators(
address tokenOwner,
bytes32 tokenId
) internal virtual

Revoke the all current operators of the tokenId token which belongs to tokenOwner.

Parameters​

NameTypeDescription
tokenOwneraddressThe address that is the owner of tokenId.
tokenIdbytes32The token to disable operator status to.

Events​

Transfer​

event Transfer(
address operator,
address from,
address to,
bytes32 tokenId,
bool force,
bytes data
)

MUST be fired when the transfer function gets executed successfuly.

Values:​

NameTypeDescription
operatoraddressThe address of operator sending tokens.
fromaddressThe address which tokens are sent.
toaddressThe recipient address.
tokenIdbytes32The token to transfer.
forceboolWhen set to true, may be any address; When set to false, address must be a contract supporting LSP1 and not revert.
databytesAdditional data the caller wants included in the emitted event, and sent in the hooks to from and to addresses.

AuthorizedOperator​

event AuthorizedOperator(
address operator,
address tokenOwner,
bytes32 tokenId
)

MUST be fired when the authorizeOperator function gets successfully executed.

Values:​

NameTypeDescription
operatoraddressThe address authorized as an operator.
tokenOwneraddressThe token owner.
tokenIdbytes32The token that operator address has access to from tokenOwner.

RevokedOperator​

event RevokedOperator(
address operator,
address tokenOwner,
bytes32 tokenId
)

MUST be fired when the revokeOperator function gets successfully executed.

Values:​

NameTypeDescription
operatoraddressThe address authorized as an operator.
tokenOwneraddressThe token owner.
tokenIdbytes32The token revoked from operator access.

References​