Skip to content

Commit

Permalink
Improve NFT collection guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugoo committed Nov 24, 2023
1 parent 07bfe9c commit 8653372
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 74 deletions.
94 changes: 29 additions & 65 deletions docs/learn/smart-contract-developers/create-nft-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,28 @@ import TabItem from '@theme/TabItem';

# Create an NFT Collection Using LSP8

This tutorial will explore how to create a collection of unique [digital assets](../../standards/tokens/LSP8-Identifiable-Digital-Asset.md).

:::info

⌨️ The full code of this example can be found in the 👾 [lukso-hardhat-template](https://github.com/CJ42/LUKSO-Hardhat-template).

:::
This tutorial explains how to create a collection of unique Digital Assets based on the [LSP8-Identifiable-Digital-Asset](../../standards/tokens/LSP8-Identifiable-Digital-Asset.md) standard.

:::note

This guide builds on top of a Hardhat project using TypeScript as described in the [Getting Started](../smart-contract-developers/getting-started.md) section.

:::

## Setup
:::info

Make sure you have the following dependencies installed:
⌨️ The full code of this example can be found in the 👾 [LUKSO-Hardhat-template](https://github.com/CJ42/LUKSO-Hardhat-template) repository.

<Tabs groupId="web3-lib">

<TabItem value="web3js" label="web3.js">
```shell
npm install @lukso/lsp-smart-contracts
```
Install hardhat-web3:
```shell
npm install --save-dev @nomiclabs/hardhat-web3 'web3@^1.0.0-beta.36'
```
:::

</TabItem>
## Setup

<TabItem value="ethersjs" label="ethers.js">
To create your custom contract based on the [LUKSO smart contracts](../../contracts/introduction.md), you will need the [`@lukso/lsp-smart-contracts`](../../tools/lsp-smart-contracts/getting-started.md) library. Go ahead and add it to your project:

```shell
npm install ethers @lukso/lsp-smart-contracts
npm install @lukso/lsp-smart-contracts
```

</TabItem>

</Tabs>

## Create the Smart Contracts

When creating smart contracts representing digital assets on LUKSO, you will need to specify the token type and data keys for the 📄 [LSP4 Digital Asset Metadata](../../standards/tokens/LSP4-Digital-Asset-Metadata) that will be stored in the 🗂️ [ERC725Y](../../standards/lsp-background/erc725.md#erc725y-generic-data-keyvalue-store) storage of the Digital Asset. There are three different token types:
Expand All @@ -61,7 +42,7 @@ When creating smart contracts representing digital assets on LUKSO, you will nee
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
bytes32 constant _LSP4_TOKEN_TYPE_DATA_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3; // kecca256 hash of the word `LSP4TokenType`
bytes32 constant _LSP4_TOKEN_TYPE_DATA_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3;
enum TokenType {
TOKEN,
Expand All @@ -70,6 +51,8 @@ enum TokenType {
}
```

The data key value `0xe026...` is the keccak256 hash of the word `LSP4TokenType` as defined by the [LSP2 - ERC725Y JSON Schema](../../standards/generic-standards/lsp2-json-schema.md#singleton) standard.

After defining the type of the asset and its 🗂️ [ERC725 data key](../../standards/lsp-background/erc725.md#erc725y-generic-data-keyvalue-store) you can create a custom 🌄 [LSP8 Identfiable Digital Asset Collection](../../standards/tokens/LSP8-Identifiable-Digital-Asset.md) that extends [LSP8Mintable](../../contracts/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.md) so that new assets can be created within the smart contract.

```solidity title="contracts/Example3/BasicNFTCollection.sol"
Expand Down Expand Up @@ -106,14 +89,15 @@ contract BasicNFTCollection is LSP8Mintable {
}
```

Next you define the deployment script.
## Deploy the Smart Contract

<Tabs groupId="web3-lib">
<TabItem value="ethersjs" label="ethers.js">
The contract is ready, it's time to deploy it. You can easily do it with hardhat deployment script.

<!-- prettier-ignore-start -->

```js title="scripts/deploy.ts"
import { ethers } from "hardhat";

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

async function deployLSP8Collection() {
Expand All @@ -124,7 +108,7 @@ async function deployLSP8Collection() {
"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")
Expand All @@ -134,53 +118,33 @@ deployLSP8Collection().catch((error) => {
console.error(error);
process.exitCode = 1;
});

```
<!-- prettier-ignore-end -->
</TabItem>
<TabItem value="web3js" label="web3.js">

Add the following to your `hardhat.config.ts`:
If you get issues related to `typechain-types`, you need to generate the types with:

```js
import '@nomiclabs/hardhat-web3';
```
npx hardhat typechain
```

Write your deployment script:

```js

import { ethers, web3 } from "hardhat";
import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types";
<!-- prettier-ignore-end -->

async function deployLSP8Collection() {
const accounts = await web3.eth.getAccounts();
const deployer = await ethers.getSigner(accounts[0])
Finally, run the deploy script:

const nftCollection: BasicNFTCollection = await new BasicNFTCollection__factory(deployer).deploy(
"NFT Collection Name", // collection name
"NFT", // collection symbol
deployer.address
);
```sh
npx hardhat run --network luksoTestnet scripts/deploy.ts
```

const nftCollectionAddress = await nftCollection.getAddress()
console.log("NFT Collection deployed to:", nftCollectionAddress)
console.log("Check the block explorer to see the deployed contract")
}
:::tip

deployLSP8Collection().catch((error) => {
console.error(error);
process.exitCode = 1;
});
The [Create a deploy script](./create-lsp7-token#create-a-deploy-script.md) section of the Create LSP7 Token guide gives more details and information about how to deploy the contracts.

```
:::

</TabItem>
</Tabs>
## View your NFT Collection

## Check Your NFT Collection
You can now use the contract address to check the deployment on the [testnet execution block explorer](https://explorer.execution.testnet.lukso.network/)

You can now check out your NFT collection on the [execution block explorer](https://explorer.execution.testnet.lukso.network/) using the address output to the web console during deployment.
<!-- TODO: add link to NFT marketplaces / dapp that can read such NFTs -->

## References

Expand Down
26 changes: 17 additions & 9 deletions docs/learn/smart-contract-developers/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Smart contract developer, welcome to the LUKSO documentation! The LUKSO ecosyste
As LUKSO is an EVM-based Blockchain, all tools and tutorials for Ethereum also work well for LUKSO. The following tutorial will teach you how to:

- set up a [Hardhat](https://hardhat.org/) installation (using TypeScript)
- install the [`@lukso/lsp-smart-contracts`](https://www.npmjs.com/package/@lukso/lsp-smart-contracts) package (using version 0.11.0-rc.1)
- create a basic [`LSP7DigitalAsset` (token)](../../standards/tokens/LSP7-Digital-Asset.md) contract
- install the [`@lukso/lsp-smart-contracts`](https://www.npmjs.com/package/@lukso/lsp-smart-contracts) package.
- deploy it on [LUKSO Testnet](../../networks/testnet/parameters).

If you need more low level information about our contracts, you can check the dedicated [contracts](../../contracts/introduction.md) section.
Expand All @@ -22,7 +21,7 @@ Happy coding 🧙

The first thing to do is to [create a new Hardhat project](https://hardhat.org/hardhat-runner/docs/getting-started#quick-start) that will use TypeScript:

```bash title="Setup new hardhat project"
```bash
mkdir lukso-app
cd lukso-app
npx hardhat
Expand All @@ -38,7 +37,7 @@ To work in the best condition possible, we will install libraries that includes

```bash
npm i -D dotenv
npm i -s @lukso/lsp-smart-contracts@0.11.0-rc.1
npm i -s @lukso/lsp-smart-contracts@0.12.1
```

Update your `package.json` with the following:
Expand Down Expand Up @@ -72,6 +71,10 @@ UP_ADDR=0x...

We now have a base Hardhat setup that we can use to develop and deploy our smart contracts.

## Get testnet LYXt

To pay for the deployment fees, you need LYXt. You can request some from the [LUKSO Testnet faucet](https://faucet.testnet.lukso.network/)

## Deploy your contracts on the LUKSO Testnet

:::info
Expand All @@ -80,7 +83,15 @@ By default, the deployment will be to your local network. If you want to deploy

:::

```js
```js title="hardhat.config.ts"
// ...
import { NetworkUserConfig } from 'hardhat/types';

import * as dotenv from 'dotenv';
dotenv.config();

// ...

function getTestnetChainConfig(): NetworkUserConfig {
const config: NetworkUserConfig = {
url: 'https://rpc.testnet.lukso.network',
Expand All @@ -93,11 +104,8 @@ function getTestnetChainConfig(): NetworkUserConfig {

return config;
}
```

Also add a definition for the testnet in the `HardhatUserConfig`:

```js
// Edit the default config object so it matches this one:
const config: HardhatUserConfig = {
solidity: {
version: '0.8.19',
Expand Down

0 comments on commit 8653372

Please sign in to comment.