Skip to main content

Create an NFT Collection Using LSP8

This tutorial explains how to create a collection of unique Digital Assets based on the LSP8-Identifiable-Digital-Asset standard.

note

This guide builds on top of a Hardhat project using TypeScript as described in the Getting Started section.

tip

The full code of this example can be found in the smart contract section of the ðŸ‘ū lukso-playground repository.

Setup​

To create your custom contract based on the LUKSO smart contracts, you will need the @lukso/lsp-smart-contracts library. Go ahead and add it to your project:

npm install @lukso/lsp-smart-contracts

Create the Smart Contracts​

When creating smart contracts representing digital assets on LUKSO, you need to specify the type of token you are deploying. This is done by setting the LSP4TokenType data key stored in the 🗂ïļ ERC725Y storage of the Digital Asset. There are three different token types:

  • 0 = Token
  • 1 = NFT
  • 2 = Collection

For this example we will use the Collection token type. You can create a custom 🌄 LSP8 Identfiable Digital Asset Collection that extends LSP8Mintable so that new assets can be created within the smart contract.

contracts/Example3/BasicNFTCollection.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

// modules
import {
LSP8Mintable
} from "@lukso/lsp-smart-contracts/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol";

// constants
import {
_LSP8_TOKENID_FORMAT_NUMBER
} from "@lukso/lsp-smart-contracts/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
import {
_LSP4_TOKEN_TYPE_COLLECTION
} from "@lukso/lsp-smart-contracts/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol";


contract BasicNFTCollection is LSP8Mintable {
constructor(
string memory nftCollectionName,
string memory nftCollectionSymbol,
address contractOwner
)
LSP8Mintable(
nftCollectionName, // NFT collection name
nftCollectionSymbol, // NFT collection symbol
contractOwner, // owner of the NFT contract (the address that controls it, sets metadata, can transfer the ownership of the contract)
_LSP4_TOKEN_TYPE_COLLECTION, // type of the token is collection
_LSP8_TOKENID_FORMAT_NUMBER // format of each `tokenId`s is number (represented as bytes32)
)
{}
}

Deploy the Smart Contract​

The contract is ready, it's time to deploy it. You can easily do it with hardhat deployment script.

scripts/deploy.ts
import { ethers } from "hardhat";

import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types";

async function deployLSP8Collection() {
const accounts = await ethers.getSigners();
const deployer = accounts[0];

const nftCollection: BasicNFTCollection = await new BasicNFTCollection__factory(deployer).deploy(
"NFT Collection Name", // collection name
"NFT", // collection symbol
deployer.address
);
const nftCollectionAddress = await nftCollection.getAddress()
console.log("NFT Collection deployed to:", nftCollectionAddress)
console.log("Check the block explorer to see the deployed contract")
}

deployLSP8Collection().catch((error) => {
console.error(error);
process.exitCode = 1;
});

If you get issues related to typechain-types, you need to generate the types with:

npx hardhat typechain

Finally, run the deploy script:

npx hardhat run --network luksoTestnet scripts/deploy.ts
tip

The Create a deploy script section of the Create LSP7 Token guide gives more details and information about how to deploy the contracts.

View your NFT Collection​

You can now use the contract address to check the deployment on the testnet execution block explorer

References​