Skip to content

Commit 36a1c6c

Browse files
nhussein110xLuccaeshaben
committed
Add "Deploy a NFT" with remix tutorial (#340)
* fix: boiler plate added * add: wip * fix: complete tutorial finished + images * fix: adding link to OZ * fix: moving smart contract to code snippet * fix: wording * fix: adding tip to mention oz contracts wizards * fix: wording * Apply suggestions from code review Co-authored-by: 0xLucca <[email protected]> * fix: feedback * Apply suggestions from code review Co-authored-by: 0xLucca <[email protected]> * fix: wording * Apply suggestions from code review Co-authored-by: Erin Shaben <[email protected]> * Update tutorials/smart-contracts/deploy-nft.md Co-authored-by: Erin Shaben <[email protected]> * fix: bold list items * fix: wording * fix: wording --------- Co-authored-by: 0xLucca <[email protected]> Co-authored-by: Erin Shaben <[email protected]>
1 parent 39e293c commit 36a1c6c

20 files changed

+168
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
// Compatible with OpenZeppelin Contracts ^5.0.0
3+
pragma solidity ^0.8.22;
4+
5+
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
6+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
7+
8+
contract MyToken is ERC721, Ownable {
9+
uint256 private _nextTokenId;
10+
11+
constructor(address initialOwner)
12+
ERC721("MyToken", "MTK")
13+
Ownable(initialOwner)
14+
{}
15+
16+
function safeMint(address to) public onlyOwner {
17+
uint256 tokenId = _nextTokenId++;
18+
_safeMint(to, tokenId);
19+
}
20+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tutorials/.pages

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ nav:
44
- polkadot-sdk
55
- interoperability
66
- onchain-governance
7+
- smart-contracts

tutorials/smart-contracts/.pages

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title: Smart Contracts
2+
nav:
3+
- index.md
4+
- 'Deploy an NFT': deploy-nft.md
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: Deploy an NFT to Asset Hub
3+
description: Deploy an NFT on Asset Hub using PolkaVM and OpenZeppelin. Learn how to compile, deploy, and interact with your contract using Polkadot Remix IDE.
4+
---
5+
6+
# Deploy an NFT to Asset Hub
7+
8+
## Introduction
9+
10+
Non-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification. Asset Hub supports EVM-compatible smart contracts through PolkaVM, enabling straightforward NFT deployment.
11+
12+
This tutorial guides you through deploying an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\_blank} NFT contract on the Westend TestNet using the [Polkadot Remix IDE](https://remix.polkadot.io){target=\_blank}, a web-based development environment. It uses [OpenZeppelin's NFT contracts]({{ dependencies.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.open_zeppelin_contracts.version}}){target=\_blank} implementation to ensure security and standard compliance.
13+
14+
## Prerequisites
15+
16+
Before starting, make sure you have:
17+
18+
- MetaMask installed and connected to Westend Asset Hub
19+
- A funded account with some WND tokens (you can get them from the [Westend Faucet](https://faucet.polkadot.io/westend?parachain=1000){target=\_blank})
20+
- Basic understanding of Solidity and NFTs
21+
22+
## Create the NFT Contract
23+
24+
To create the NFT contract, you can follow the steps below:
25+
26+
1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io/){target=\_blank}
27+
2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyNFT.sol`
28+
29+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-1.webp)
30+
31+
3. Now, paste the following NFT contract code into the editor
32+
33+
```solidity title="MyNFT.sol"
34+
--8<-- 'code/tutorials/smart-contracts/deploy-nft/MyNFT.sol'
35+
```
36+
37+
The key components of the code above are:
38+
39+
- Contract imports
40+
41+
- [**`ERC721.sol`**]({{ dependencies.open_zeppelin_contracts.repository_url }}/blob/{{ dependencies.open_zeppelin_contracts.version }}/contracts/token/ERC721/ERC721.sol){target=\_blank} - the base contract for non-fungible tokens, implementing core NFT functionality like transfers and approvals
42+
- [**`Ownable.sol`**]({{ dependencies.open_zeppelin_contracts.repository_url }}/blob/{{ dependencies.open_zeppelin_contracts.version }}/contracts/access/Ownable.sol){target=\_blank} - provides basic authorization control, ensuring only the contract owner can mint new tokens
43+
44+
- Constructor parameters
45+
46+
- **`initialOwner`** - sets the address that will have administrative rights over the contract
47+
- **`"MyToken"`** - the full name of your NFT collection
48+
- **`"MTK"`** - the symbol representing your token in wallets and marketplaces
49+
50+
- Key functions
51+
52+
- [**`_safeMint(to, tokenId)`**]({{ dependencies.open_zeppelin_contracts.repository_url }}/blob/{{ dependencies.open_zeppelin_contracts.version }}/contracts/token/ERC721/ERC721.sol#L304){target=\_blank} - an internal function from `ERC721` that safely mints new tokens. It includes checks to ensure the recipient can handle ERC721 tokens (important when minting smart contracts)
53+
- Inherited [Standard ERC721](https://ethereum.org/en/developers/docs/standards/tokens/erc-721/){target=\_blank} functions:
54+
- **`transferFrom(address from, address to, uint256 tokenId)`** - transfers a specific NFT from one address to another
55+
- **`safeTransferFrom(address from, address to, uint256 tokenId)`** - safely transfers an NFT, including additional checks to prevent loss
56+
- **`approve(address to, uint256 tokenId)`** - grants permission for another address to transfer a specific NFT
57+
- **`setApprovalForAll(address operator, bool approved)`** - allows an address to manage all of the owner's NFTs
58+
- **`balanceOf(address owner)`** - returns the number of NFTs owned by a specific address
59+
- **`ownerOf(uint256 tokenId)`** - returns the current owner of a specific NFT
60+
61+
!!! tip
62+
Use the [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\_blank} to generate customized smart contracts quickly. Simply configure your contract, copy the generated code, and paste it into Polkadot Remix IDE for deployment.
63+
64+
## Compile the Contract
65+
66+
Compilation is an stage that converts your Solidity source code into bytecode suitable for deployment on the blockchain. Throughout this process, the compiler examines your contract for syntax errors, verifies type safety, and produces the machine-readable instructions required for executing on the blockchain.
67+
68+
1. Select the **Solidity Compiler** plugin from the left panel
69+
70+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-3.webp)
71+
72+
2. Click in the **Compile MyNFT.sol** button
73+
74+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-4.webp)
75+
76+
3. If the compilation succeeded, you can see a green checkmark indicating success in the **Solidity Compiler** icon
77+
78+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-5.webp)
79+
80+
## Deploy the Contract
81+
82+
Deployment is the process of uploading your compiled smart contract to the blockchain, allowing for interaction. During deployment, you will instantiate your contract on the blockchain, which involves:
83+
84+
1. Select the **Deploy & Run Transactions** plugin from the left panel
85+
86+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-6.webp)
87+
88+
2. Configure the deployment settings
89+
1. From the **ENVIRONMENT** dropdown, select **Westend Testnet - MetaMask**
90+
2. From the **ACCOUNT** dropdown, select the account you want to use for the deploy
91+
92+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-7.webp)
93+
94+
3. Configure the contract parameters
95+
1. Enter the address that will own the deployed NFT.
96+
2. Click the **Deploy** button to initiate the deployment
97+
98+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-8.webp)
99+
100+
4. MetaMask will pop up - review the transaction details. Click **Confirm** to deploy your contract
101+
102+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-9.webp){: .browser-extension}
103+
104+
If the deployment process succeeded, you will see the following output in the terminal:
105+
106+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-10.webp)
107+
108+
## Interact with Your NFT Contract
109+
110+
Once deployed, you can interact with your contract through Remix:
111+
112+
1. Find your contract under **Deployed/Unpinned Contracts**, and click it to expand the available methods for the contract
113+
114+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-11.webp)
115+
116+
2. To mint an NFT
117+
118+
1. Click on the contract to expand its associated methods
119+
2. Expand the **safeMint** function
120+
3. Enter the recipient address
121+
4. Click **Transact**
122+
123+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-12.webp)
124+
125+
3. Click **Confirm** to confirm the transaction in MetaMask
126+
127+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-13.webp){: .browser-extension}
128+
129+
If the transaction is successful, the terminal will display the following output, which details the information about the transaction, including the transaction hash, the block number, the associated logs, and so on.
130+
131+
![](/images/tutorials/smart-contracts/deploy-nft/deploy-nft-14.webp)
132+
133+
Feel free to explore and interact with the contract's other functions using the same approach - selecting the method, providing any required parameters, and confirming the transaction through MetaMask when needed.

tutorials/smart-contracts/index.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Smart Contracts
3+
description: TODO
4+
template: index-page.html
5+
---
6+
7+
# Smart Contracts

variables.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ dependencies:
33
open_zeppelin:
44
repository_url: https://github.com/OpenZeppelin/polkadot-runtime-templates
55
version: v1.0.0
6+
open_zeppelin_contracts:
7+
repository_url: https://github.com/OpenZeppelin/openzeppelin-contracts
8+
version: v5.0.0
69
chopsticks:
710
repository_url: https://github.com/AcalaNetwork/chopsticks
811
version: 0.13.1

0 commit comments

Comments
 (0)