Skip to main content

Digital Assets

The Digital Asset (Token and NFT 2.0) contracts are the newest advanced version of the existing token standards. They come with many features that enhance the security and the overall user experience and compatibility with ERC725Accounts and Universal Receivers.

Comparisons with ERC20 / ERC721​

The interfaces of LSP7 and LSP8 have some differences compared to ERC20 and ERC721. Their functions are simpler, more straight forward and unified.

Similar function names

Both functions in LSP7 and LSP8 have the same name (transfer) to transfer assets. This is easier compared to ERC20 and ERC721 that use different naming (transfer for ERC20 vs transferFrom in ERC721 to transfer tokens as the token owner).

The table below highlights these differences:

DescriptionERC20LSP7
Transferring tokens as an owner.transfer(address,uint256)transfer(address,address,uint256,bool,bytes)
Transferring tokens as an operator.transferFrom(address,address,uint256)
Approving an operator to spend tokens on behalf of the owner.approve(address,uint256)authorizeOperator(address,uint256)
DescriptionERC721LSP8
Transferring tokens as an owner.transferFrom(address,address,uint256)
safeTransferFrom(address,address,uint256)
safeTransferFrom(address,address,uint256,bytes)
transfer(address,address,bytes32,bool,bytes)
Transferring tokens as an operator.
Approving an operator to spend tokens on behalf of the owner.approve(address,uint256)authorizeOperator(address,bytes32)

LSP4 Digital Asset Metadata​

The LSP4DigitalAssetMetadata is a contract that sets the Token-Metadata (name and symbol) for the LSP7DigitalAsset and LSP8IdentifiableDigitalAsset token contracts.

Since it uses ERC725Y General Data Key/Value Store to set the metadata, any information can be added (e.g: list of creators, JSON files, etc).

LSP7 Digital Asset​

The LSP7DigitalAsset contract represents digital assets for fungible tokens where minting and transferring are specified with an amount of tokens. Their functions were inspired from ERC20 and ERC1155 with more upgraded features.

An LSP7 can serves as:

  • a Divisible Token Contract when isNonDivisible bool is set to false in the constructor(...)
  • otherwise serves as a Non-Divisible Token Contract.

This can be useful to set isNonDivisible to true, rather than deploying a LSP8 contract to achieve the same goal.

Create a Fungible Token​

// MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol";

contract MyToken is LSP7DigitalAsset {
// 4th argument (false) marks that this contract serves as a Fungible Token and not as a NFT.
constructor() LSP7DigitalAsset("MyToken","MTKN",msg.sender,false) {
// ..
}

function mint() public {
_mint(...);
}
}

LSP8 Identifiable Digital Asset​

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).

Checking if the Metadata of a tokenId changed​

Because LSP8 uses ERC725Y under the hood, the URI pointing to the metadata of a specific tokenId can be changed inside the ERC725Y storage.

This can be done via the functions setData(bytes32,bytes) or setDataBatch(bytes32[],bytes[]).

Since this function emits the DataChanged event, you can listen for this event in the LSP8 contract to check if the URI pointing of the tokenId metadata has changed. You can do so by filtering the first parameter dataKey with:

LSP8MetadataTokenURI:<first 20 bytes of tokenId>

If your LSP8 contract uses a specific URI for each tokenId.

Example of filtering with LSP8MetadataTokenURI:tokenId

Using the following tokenId as an example: 0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff

LSP8MetadataTokenURI data key prefix = 0x0x4690256ef7e93288012f0000

You can filter the DataChanged event with the following dataKey:

  | LSP8MetadataTokenURI |      first 20 bytes of tokenId        |
0x4690256ef7e93288012f00001111222233334444555566667777888899990000

Note on LSP7 and LSP8 implementations​

LSP7DigitalAsset.sol and LSP8IdentifiableDigitalAsset.sol are abstract contracts that are not deployable as they are, because they do not contain any public functions by default to manage token supply (e.g: no public mint(...) or burn(...) functions). You can either:

  • use LSP7Mintable or LSP8Mintable, a preset contract that contains a public mint(...) function callable only by the contract's owner.
  • or extend the LSP7DigitalAsset / LSP8IdentifiableDigitalAsset contract and create your own supply mechanism by defining public methods that use the internal _mint(...) and _burn(...) functions.