Skip to main content

πŸ—ƒοΈ Retrieve Token Type

To detect if an asset is a Token, an NFT or a Collection, we can check the value stored in the LSP4TokenType data key.

This guide show you how to retrieve the token type of a deployed token contract using the getData(...) function, passing the LSP4TokenType data key as a parameter.

We will show you example with 3 different libraries: erc725.js, web3.js and ethers.js

Introduction​

Token Types are beneficial because of the wide range of asset use cases. The LSP7 and LSP8 can both be used as NFTs.

  • LSP7 can be used for building NFTs where each individual items have the same metadata, and users are allowed to mint multiple NFTs at once.
  • In comparison, LSP8 is mainly used for NFTs with unique properties per item (like phygitals, dynamic NFTs or unique collections like Chillwhales).
Convenience Tools

You can use the βš’οΈ erc725.js library, which automatically decodes ERC725Y storage keys for you.

If you are using a regular contract instance from Ethers or Web3, you can use the data keys from the lsp-smart-contracts library by importing the ERC725YDataKeys constant.

npm install @erc725/erc725.js

Retrieve the Token Type​

After setting up the contract, retrieving its token type is as simple as making one contract call to the getData(...) function.

import { ERC725 } from '@erc725/erc725.js';
import lsp4Schema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json';

const myAsset = new ERC725(
lsp4Schema,
'<myAssetAddress>', // Your Asset Address
'https://4201.rpc.thirdweb.com', // LUKSO Testnet RPC
{},
);

// Retrieve the token type
const tokenType = await myAsset.getData('LSP4TokenType');
console.log(tokenType);
// 0 = Token
// 1 = NFT
// 2 = Collection