From 1817cb3afa2819fe7ac5c057a30e91e3d1549e2e Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Wed, 8 Nov 2023 11:14:36 +0100 Subject: [PATCH 01/13] create an NFT Collection using LSP8 --- .../create-nft-collection.md | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 docs/learn/smart-contract-developers/create-nft-collection.md diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md new file mode 100644 index 0000000000..a0c6297230 --- /dev/null +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -0,0 +1,114 @@ +--- +sidebar_label: '🗃 Create an NFT Collection' +sidebar_position: 4 +--- + +# Create an NFT Collection Using LSP8 + +This tutorial goes over creating a collection of collectibles, where each item is unique and has its own design. + +:::info +⌨️ The full code of this example can be found in 👾 [here](https://github.com/CJ42/LUKSO-Hardhat-template). +::: + +## Setup + +Make sure you have the following dependencies installed: + +- [`ethers.js`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) +- [`@lukso/lsp-smart-contracts`](https://github.com/lukso-network/lsp-smart-contracts/) + +## Create the Smart Contracts + +When creating digital asset smart contracts on LUKSO, you will need to specify the token type and the following data keys in the ERC725Y storage. There are three types that you can define: + +- 0 = Token +- 1 = NFT +- 2 = Collection + +```solidity title="contracts/TokenTypes.sol" +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +bytes32 constant _LSP4_TOKEN_TYPE_DATA_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3; + +enum TokenType { + TOKEN, + NFT, + COLLECTION +} + + +``` + +You will also create a custom [LSP8 Identfiable Digital Asset Collection](../../standards/tokens/LSP8-Identifiable-Digital-Asset.md) that extends [LSP8Mintable](../../contracts/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.md). + +```solidity title="contracts/MyNFTCollection.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_TYPE_NUMBER +} from "@lukso/lsp-smart-contracts/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol"; +import {_LSP4_TOKEN_TYPE_DATA_KEY, TokenType} from "../TokenTypes.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) + _LSP8_TOKENID_TYPE_NUMBER // type of NFT/ tokenIds + ) + { + // set token type + _setData(_LSP4_TOKEN_TYPE_DATA_KEY, abi.encode(TokenType.COLLECTION)); + } +} +``` + +## Deploy our NFT Collection Contract on the LUKSO Testnet + +```js +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 + ); + +} + +deployLSP8Collection().catch((error) => { + console.error(error); + process.exitCode = 1; +}); + + +``` + +## Congratulations 🥳 + +You have deployed your first LSP8 NFT Collection on the LUKSO Testnet. + +## References + +- [BuildUP #2 | Create an NFT Collection using LSP7 or LSP8 (YouTube)](https://www.youtube.com/watch?v=DMpeMswK12w) From bd63ecc60b1b6b845e90ba3bd95fac7c8a517dc5 Mon Sep 17 00:00:00 2001 From: biancabuzea200 <34369307+biancabuzea200@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:48:18 +0100 Subject: [PATCH 02/13] Update docs/learn/smart-contract-developers/create-nft-collection.md Co-authored-by: Felix Hildebrandt <61689369+fhildeb@users.noreply.github.com> --- docs/learn/smart-contract-developers/create-nft-collection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index a0c6297230..ccc55d2c3b 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -8,7 +8,7 @@ sidebar_position: 4 This tutorial goes over creating a collection of collectibles, where each item is unique and has its own design. :::info -⌨️ The full code of this example can be found in 👾 [here](https://github.com/CJ42/LUKSO-Hardhat-template). +⌨️ The full code of this example can be found in the 👾 [lukso-hardhat-template](https://github.com/CJ42/LUKSO-Hardhat-template). ::: ## Setup From 47b08617875c85c0cbb1626530ce5294582951b5 Mon Sep 17 00:00:00 2001 From: biancabuzea200 <34369307+biancabuzea200@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:48:27 +0100 Subject: [PATCH 03/13] Update docs/learn/smart-contract-developers/create-nft-collection.md Co-authored-by: Felix Hildebrandt <61689369+fhildeb@users.noreply.github.com> --- docs/learn/smart-contract-developers/create-nft-collection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index ccc55d2c3b..77bb88eb69 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -5,7 +5,7 @@ sidebar_position: 4 # Create an NFT Collection Using LSP8 -This tutorial goes over creating a collection of collectibles, where each item is unique and has its own design. +This tutorial will teach you how to create a collection of unique digital assets. :::info ⌨️ The full code of this example can be found in the 👾 [lukso-hardhat-template](https://github.com/CJ42/LUKSO-Hardhat-template). From 93d91be873b5ac47ed04279ec1db864453b84358 Mon Sep 17 00:00:00 2001 From: biancabuzea200 <34369307+biancabuzea200@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:49:14 +0100 Subject: [PATCH 04/13] Update docs/learn/smart-contract-developers/create-nft-collection.md Co-authored-by: Felix Hildebrandt <61689369+fhildeb@users.noreply.github.com> --- docs/learn/smart-contract-developers/create-nft-collection.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 77bb88eb69..d42e054989 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -18,6 +18,10 @@ Make sure you have the following dependencies installed: - [`ethers.js`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) - [`@lukso/lsp-smart-contracts`](https://github.com/lukso-network/lsp-smart-contracts/) +\```bash +npm install ethers @lukso/lsp-smart-contracts +\``` + ## Create the Smart Contracts When creating digital asset smart contracts on LUKSO, you will need to specify the token type and the following data keys in the ERC725Y storage. There are three types that you can define: From 8155c9d02c51b0966418af35d476ed8a5ce02064 Mon Sep 17 00:00:00 2001 From: biancabuzea200 <34369307+biancabuzea200@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:49:48 +0100 Subject: [PATCH 05/13] Update docs/learn/smart-contract-developers/create-nft-collection.md Co-authored-by: Felix Hildebrandt <61689369+fhildeb@users.noreply.github.com> --- .../smart-contract-developers/create-nft-collection.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index d42e054989..7eaeafa075 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -26,9 +26,9 @@ npm install ethers @lukso/lsp-smart-contracts When creating digital asset smart contracts on LUKSO, you will need to specify the token type and the following data keys in the ERC725Y storage. There are three types that you can define: -- 0 = Token -- 1 = NFT -- 2 = Collection +- `0` = Token +- `1` = NFT +- `2` = Collection ```solidity title="contracts/TokenTypes.sol" // SPDX-License-Identifier: MIT From 53b250d668db97a6e444e84e57bfdd780e5239d1 Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Thu, 9 Nov 2023 19:20:10 +0100 Subject: [PATCH 06/13] integrate feedback --- .../create-nft-collection.md | 70 ++++++++++++++++--- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 7eaeafa075..78e9e2ecdc 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -5,12 +5,18 @@ sidebar_position: 4 # Create an NFT Collection Using LSP8 -This tutorial will teach you how to create a collection of unique digital assets. +This tutorial will explore how to create a collection of unique digital assets. :::info ⌨️ The full code of this example can be found in the 👾 [lukso-hardhat-template](https://github.com/CJ42/LUKSO-Hardhat-template). ::: +:::note + +This guide builds on top of a Hartdhat project using TypeScript as described in the [Getting Started section](../smart-contract-developers/getting-started.md). + +::: + ## Setup Make sure you have the following dependencies installed: @@ -18,13 +24,13 @@ Make sure you have the following dependencies installed: - [`ethers.js`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) - [`@lukso/lsp-smart-contracts`](https://github.com/lukso-network/lsp-smart-contracts/) -\```bash +```bash npm install ethers @lukso/lsp-smart-contracts -\``` +``` ## Create the Smart Contracts -When creating digital asset smart contracts on LUKSO, you will need to specify the token type and the following data keys in the ERC725Y storage. There are three types that you can define: +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 Universal Profile. There are three different token types: - `0` = Token - `1` = NFT @@ -41,11 +47,9 @@ enum TokenType { NFT, COLLECTION } - - ``` -You will also create a custom [LSP8 Identfiable Digital Asset Collection](../../standards/tokens/LSP8-Identifiable-Digital-Asset.md) that extends [LSP8Mintable](../../contracts/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.md). +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/MyNFTCollection.sol" @@ -82,7 +86,53 @@ contract BasicNFTCollection is LSP8Mintable { } ``` -## Deploy our NFT Collection Contract on the LUKSO Testnet +## Deploy your NFT Collection Contract on the LUKSO Testnet + +:::info + +By default, the deployment will be to your local network. If you want to deploy to the LUKSO Testnet, you will need to add the LUKSO Testnet network in your `hardhat.config.ts`. + +::: + +```js +function getTestnetChainConfig(): NetworkUserConfig { + const config: NetworkUserConfig = { + url: 'https://rpc.testnet.lukso.network', + chainId: 4201, + }; + + if (process.env.PRIVATE_KEY !== undefined) { + config['accounts'] = [process.env.PRIVATE_KEY]; + } + + return config; +} +``` + +Also add a definition for the testnet in the `HardhatUserConfig`: + +```js +const config: HardhatUserConfig = { + solidity: { + version: '0.8.19', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + typechain: { + outDir: 'typechain-types', + target: 'ethers-v6', + }, + networks: { + luksoTestnet: getTestnetChainConfig(), + }, +}; +``` + +Next you define the deployment script: ```js import { ethers } from "hardhat"; @@ -109,9 +159,9 @@ deployLSP8Collection().catch((error) => { ``` -## Congratulations 🥳 +## Check Your NFT Collection -You have deployed your first LSP8 NFT Collection on the LUKSO Testnet. +You can now check your NFT collection using the [execution block explorer](https://explorer.execution.testnet.lukso.network/). ## References From 0d69c3e4bf68bb82f57f7ca00de622b707a4bb9a Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Fri, 10 Nov 2023 10:50:52 +0100 Subject: [PATCH 07/13] minor improvements --- .../smart-contract-developers/create-nft-collection.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 78e9e2ecdc..6ef49195fb 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -5,15 +5,17 @@ sidebar_position: 4 # Create an NFT Collection Using LSP8 -This tutorial will explore how to create a collection of unique digital assets. +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). + ::: :::note -This guide builds on top of a Hartdhat project using TypeScript as described in the [Getting Started section](../smart-contract-developers/getting-started.md). +This guide builds on top of a Hardhat project using TypeScript as described in the [Getting Started section](../smart-contract-developers/getting-started.md). ::: @@ -52,7 +54,6 @@ enum TokenType { 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/MyNFTCollection.sol" - // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; From f53dd4ecc45ea4b6aa76c495b878c6343fab2f3c Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Fri, 10 Nov 2023 10:57:06 +0100 Subject: [PATCH 08/13] move `hardhat.config.ts` part to getting started --- .../create-nft-collection.md | 46 ------------------- .../getting-started.md | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 6ef49195fb..590bd84eff 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -87,52 +87,6 @@ contract BasicNFTCollection is LSP8Mintable { } ``` -## Deploy your NFT Collection Contract on the LUKSO Testnet - -:::info - -By default, the deployment will be to your local network. If you want to deploy to the LUKSO Testnet, you will need to add the LUKSO Testnet network in your `hardhat.config.ts`. - -::: - -```js -function getTestnetChainConfig(): NetworkUserConfig { - const config: NetworkUserConfig = { - url: 'https://rpc.testnet.lukso.network', - chainId: 4201, - }; - - if (process.env.PRIVATE_KEY !== undefined) { - config['accounts'] = [process.env.PRIVATE_KEY]; - } - - return config; -} -``` - -Also add a definition for the testnet in the `HardhatUserConfig`: - -```js -const config: HardhatUserConfig = { - solidity: { - version: '0.8.19', - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, - typechain: { - outDir: 'typechain-types', - target: 'ethers-v6', - }, - networks: { - luksoTestnet: getTestnetChainConfig(), - }, -}; -``` - Next you define the deployment script: ```js diff --git a/docs/learn/smart-contract-developers/getting-started.md b/docs/learn/smart-contract-developers/getting-started.md index 80eb3f0c07..8c5e3ca53e 100644 --- a/docs/learn/smart-contract-developers/getting-started.md +++ b/docs/learn/smart-contract-developers/getting-started.md @@ -71,3 +71,49 @@ UP_ADDR=0x... ``` We now have a base Hardhat setup that we can use to develop and deploy our smart contracts. + +## Deploy your contracts on the LUKSO Testnet + +:::info + +By default, the deployment will be to your local network. If you want to deploy to the LUKSO Testnet, you will need to add the LUKSO Testnet network in your `hardhat.config.ts`. + +::: + +```js +function getTestnetChainConfig(): NetworkUserConfig { + const config: NetworkUserConfig = { + url: 'https://rpc.testnet.lukso.network', + chainId: 4201, + }; + + if (process.env.PRIVATE_KEY !== undefined) { + config['accounts'] = [process.env.PRIVATE_KEY]; + } + + return config; +} +``` + +Also add a definition for the testnet in the `HardhatUserConfig`: + +```js +const config: HardhatUserConfig = { + solidity: { + version: '0.8.19', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + typechain: { + outDir: 'typechain-types', + target: 'ethers-v6', + }, + networks: { + luksoTestnet: getTestnetChainConfig(), + }, +}; +``` From 94da74c09a4063ab2c263238d394e06f0daf4cdf Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Fri, 10 Nov 2023 14:33:19 +0100 Subject: [PATCH 09/13] add web3 version --- .../create-nft-collection.md | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 590bd84eff..c30977de80 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -3,6 +3,9 @@ sidebar_label: '🗃 Create an NFT Collection' sidebar_position: 4 --- +import Tabs from '@theme/Tabs'; +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). @@ -15,7 +18,7 @@ This tutorial will explore how to create a collection of unique [digital assets] :::note -This guide builds on top of a Hardhat project using TypeScript as described in the [Getting Started section](../smart-contract-developers/getting-started.md). +This guide builds on top of a Hardhat project using TypeScript as described in the [Getting Started](../smart-contract-developers/getting-started.md) section. ::: @@ -87,23 +90,79 @@ contract BasicNFTCollection is LSP8Mintable { } ``` -Next you define the deployment script: +Next you define the deployment script. + + + + ```js 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; +}); + +``` + + + + +Swap to the latest version of node; + +```sh +nvm install node +nvm use node +``` + +Install hardhat web3; + +```sh +npm install --save-dev @nomiclabs/hardhat-web3 'web3@^1.0.0-beta.36' +``` + +Add the following to your hardhat.config.ts; + +```js +import '@nomiclabs/hardhat-web3'; +``` + +Write your deployment script; + +```js + +import { ethers, web3 } from "hardhat"; +import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types"; + +async function deployLSP8Collection() { + const accounts = await web3.eth.getAccounts(); + const deployer = await ethers.getSigner(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) => { @@ -111,12 +170,14 @@ deployLSP8Collection().catch((error) => { process.exitCode = 1; }); - ``` + + + ## Check Your NFT Collection -You can now check your NFT collection using the [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. ## References From 4fb8090c5aeb078bdbe3413bf26b7132f363eb9c Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Mon, 13 Nov 2023 23:07:16 +1000 Subject: [PATCH 10/13] add explanation for `_LSP4_TOKEN_TYPE_DATA_KEY` --- docs/learn/smart-contract-developers/create-nft-collection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index c30977de80..75cba8e1f6 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -45,7 +45,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; +bytes32 constant _LSP4_TOKEN_TYPE_DATA_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3; // kecca256 hash of the word `LSP4TokenType` enum TokenType { TOKEN, From 291e851783f308087f455cf78f88118ad41c338d Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Tue, 21 Nov 2023 00:47:46 +1000 Subject: [PATCH 11/13] minor fixes --- .../smart-contract-developers/create-nft-collection.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 75cba8e1f6..239f83273d 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -26,7 +26,7 @@ This guide builds on top of a Hardhat project using TypeScript as described in t Make sure you have the following dependencies installed: -- [`ethers.js`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) +- [`ethers.js v6`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) - [`@lukso/lsp-smart-contracts`](https://github.com/lukso-network/lsp-smart-contracts/) ```bash @@ -35,7 +35,7 @@ npm install ethers @lukso/lsp-smart-contracts ## 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 Universal Profile. There are three different token types: +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: - `0` = Token - `1` = NFT @@ -96,7 +96,7 @@ Next you define the deployment script. -```js +```js title="deployLSP8Collection.ts" import { ethers } from "hardhat"; import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types"; @@ -104,7 +104,7 @@ async function deployLSP8Collection() { const accounts = await ethers.getSigners(); const deployer = accounts[0]; - const nftCollection: BasicNFTCollection = await new BasicNFTCollection\_\_factory(deployer).deploy( + const nftCollection: BasicNFTCollection = await new BasicNFTCollection__factory(deployer).deploy( "NFT Collection Name", // collection name "NFT", // collection symbol deployer.address From 78ad3e2e9ed504cb58ee7952cdcef6a96c54fa0f Mon Sep 17 00:00:00 2001 From: biancabuzea200 Date: Fri, 24 Nov 2023 02:33:28 +1000 Subject: [PATCH 12/13] implement feedback --- .../create-nft-collection.md | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 239f83273d..8e4ffd3ca4 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -26,13 +26,29 @@ This guide builds on top of a Hardhat project using TypeScript as described in t Make sure you have the following dependencies installed: -- [`ethers.js v6`](https://github.com/ethers-io/ethers.js/) (alternatively you can use [`web3.js`](https://github.com/web3/web3.js)) -- [`@lukso/lsp-smart-contracts`](https://github.com/lukso-network/lsp-smart-contracts/) + + + +```shell +npm install @lukso/lsp-smart-contracts +``` +Install hardhat-web3: +```shell +npm install --save-dev @nomiclabs/hardhat-web3 'web3@^1.0.0-beta.36' +``` + + -```bash + + +```shell npm install ethers @lukso/lsp-smart-contracts ``` + + + + ## 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: @@ -56,7 +72,7 @@ enum TokenType { 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/MyNFTCollection.sol" +```solidity title="contracts/Example3/BasicNFTCollection.sol" // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; @@ -96,7 +112,7 @@ Next you define the deployment script. -```js title="deployLSP8Collection.ts" +```js title="scripts/deploy.ts" import { ethers } from "hardhat"; import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types"; @@ -124,26 +140,13 @@ deployLSP8Collection().catch((error) => { -Swap to the latest version of node; - -```sh -nvm install node -nvm use node -``` - -Install hardhat web3; - -```sh -npm install --save-dev @nomiclabs/hardhat-web3 'web3@^1.0.0-beta.36' -``` - -Add the following to your hardhat.config.ts; +Add the following to your `hardhat.config.ts`: ```js import '@nomiclabs/hardhat-web3'; ``` -Write your deployment script; +Write your deployment script: ```js From 86533724025b80559ffe363caf4ad3f036b51fee Mon Sep 17 00:00:00 2001 From: Hugo Masclet Date: Fri, 24 Nov 2023 12:20:41 +0100 Subject: [PATCH 13/13] Improve NFT collection guide --- .../create-nft-collection.md | 94 ++++++------------- .../getting-started.md | 26 +++-- 2 files changed, 46 insertions(+), 74 deletions(-) diff --git a/docs/learn/smart-contract-developers/create-nft-collection.md b/docs/learn/smart-contract-developers/create-nft-collection.md index 8e4ffd3ca4..af2c08d459 100644 --- a/docs/learn/smart-contract-developers/create-nft-collection.md +++ b/docs/learn/smart-contract-developers/create-nft-collection.md @@ -8,13 +8,7 @@ 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 @@ -22,33 +16,20 @@ This guide builds on top of a Hardhat project using TypeScript as described in t ::: -## 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. - - - -```shell -npm install @lukso/lsp-smart-contracts -``` -Install hardhat-web3: -```shell -npm install --save-dev @nomiclabs/hardhat-web3 'web3@^1.0.0-beta.36' -``` +::: - +## Setup - +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 ``` - - - - ## 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: @@ -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, @@ -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" @@ -106,14 +89,15 @@ contract BasicNFTCollection is LSP8Mintable { } ``` -Next you define the deployment script. +## Deploy the Smart Contract - - +The contract is ready, it's time to deploy it. You can easily do it with hardhat deployment script. + ```js title="scripts/deploy.ts" import { ethers } from "hardhat"; + import {BasicNFTCollection, BasicNFTCollection__factory} from "../typechain-types"; async function deployLSP8Collection() { @@ -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") @@ -134,53 +118,33 @@ deployLSP8Collection().catch((error) => { console.error(error); process.exitCode = 1; }); - ``` - - - -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"; + -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. -``` +::: - - +## 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. + ## References diff --git a/docs/learn/smart-contract-developers/getting-started.md b/docs/learn/smart-contract-developers/getting-started.md index 8c5e3ca53e..2e1e6fe738 100644 --- a/docs/learn/smart-contract-developers/getting-started.md +++ b/docs/learn/smart-contract-developers/getting-started.md @@ -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. @@ -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 @@ -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: @@ -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 @@ -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', @@ -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',