diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/Storage.sol b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/Storage.sol new file mode 100644 index 000000000..49cb1444a --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/Storage.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.9; + +contract Storage { + uint256 private storedNumber; + + function store(uint256 num) public { + storedNumber = num; + } + + function retrieve() public view returns (uint256) { + return storedNumber; + } +} diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/compile-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/compile-output.html new file mode 100644 index 000000000..54128743a --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/compile-output.html @@ -0,0 +1,7 @@ +
+ npx hardhat compile + Downloading solc 0.8.28 + Downloading solc 0.8.28 (WASM build) + Compiled 1 Solidity file with solc 0.8.28 (evm target: cancun) + +
diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/deploy-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/deploy-output.html new file mode 100644 index 000000000..408a91af2 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/deploy-output.html @@ -0,0 +1,15 @@ +
+ npx hardhat ignition deploy ignition/modules/Storage.ts --network polkadotHubTestnet + โœ” Confirm deploy to network polkadotTestnet (420420420)? โ€ฆ yes +   + Hardhat Ignition ๐Ÿš€ +   + Deploying [ StorageModule ] +   + [ StorageModule ] successfully deployed ๐Ÿš€ +   + Deployed Addresses +   + Storage - 0x12345..... + +
\ No newline at end of file diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/hardhat.config.ts b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/hardhat.config.ts new file mode 100644 index 000000000..5194f0313 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/hardhat.config.ts @@ -0,0 +1,47 @@ +import type { HardhatUserConfig } from 'hardhat/config'; + +import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; +import { configVariable } from 'hardhat/config'; + +const config: HardhatUserConfig = { + plugins: [hardhatToolboxViemPlugin], + solidity: { + profiles: { + default: { + version: '0.8.28', + }, + production: { + version: '0.8.28', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + }, + }, + networks: { + hardhatMainnet: { + type: 'edr-simulated', + chainType: 'l1', + }, + hardhatOp: { + type: 'edr-simulated', + chainType: 'op', + }, + sepolia: { + type: 'http', + chainType: 'l1', + url: configVariable('SEPOLIA_RPC_URL'), + accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], + }, + polkadotHubTestnet: { + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + chainId: 420420422, + accounts: [configVariable('PRIVATE_KEY')], + }, + }, +}; + +export default config; diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/storage.ts b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/storage.ts new file mode 100644 index 000000000..20cdcf3c7 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/storage.ts @@ -0,0 +1,6 @@ +import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; + +export default buildModule('StorageModule', (m) => { + const storage = m.contract('Storage'); + return { storage }; +}); diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/compile-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/compile-output.html new file mode 100644 index 000000000..525fade08 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/compile-output.html @@ -0,0 +1,7 @@ +
+ npx hardhat compile + Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 + Successfully generated 62 typings! + Compiled 21 Solidity files successfully (evm target: paris). + +
diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/deploy-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/deploy-output.html new file mode 100644 index 000000000..5a29c3a74 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/deploy-output.html @@ -0,0 +1,21 @@ +
+ npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + โœ” Confirm deploy to network polkadotTestnet (420420420)? โ€ฆ yes +   + Hardhat Ignition ๐Ÿš€ +   + Deploying [ TokenModule ] +   + Batch #1 + Executed TokenModule#MyToken +   + Batch #2 + Executed TokenModule#MyToken.mint +   + [ TokenModule ] successfully deployed ๐Ÿš€ +   + Deployed Addresses +   + TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 + +
diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/testing-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/testing-output.html new file mode 100644 index 000000000..2be1b9f77 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/testing-output.html @@ -0,0 +1,17 @@ +
+ npx hardhat test --network polkadotTestnet + +   MyToken +     Deployment +       โœ” Should have correct name and symbol +       โœ” Should set the right owner +       โœ” Should have zero initial supply +     Minting +       โœ” Should allow owner to mint tokens +       โœ” Should increase total supply on mint +     Multiple mints +       โœ” Should correctly track balance after multiple mints + +   6 passing (369ms) + +
diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.sol b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.sol new file mode 100644 index 000000000..0bcab0501 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; + +contract MyNFT is ERC721, Ownable { + uint256 private _nextTokenId; + + constructor( + address initialOwner + ) ERC721("MyToken", "MTK") Ownable(initialOwner) {} + + function safeMint(address to) public onlyOwner { + uint256 tokenId = _nextTokenId++; + _safeMint(to, tokenId); + } +} diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.ts b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.ts new file mode 100644 index 000000000..0be0a559c --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.ts @@ -0,0 +1,7 @@ +import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; + +export default buildModule('MyNFTModule', (m) => { + const initialOwner = m.getParameter('initialOwner', 'INSERT_OWNER_ADDRESS'); + const myNFT = m.contract('MyNFT', [initialOwner]); + return { myNFT }; +}); diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/compile-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/compile-output.html new file mode 100644 index 000000000..17867ca16 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/compile-output.html @@ -0,0 +1,7 @@ +
+ npx hardhat compile + Downloading solc 0.8.28 + Downloading solc 0.8.28 (WASM build) + Compiled 1 Solidity file with solc 0.8.28 (evm target: cancun) + +
\ No newline at end of file diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/deploy-output.html b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/deploy-output.html new file mode 100644 index 000000000..40137cd7c --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/deploy-output.html @@ -0,0 +1,21 @@ +
+ npx hardhat ignition deploy ignition/modules/MyNFT.ts --network polkadotHubTestnet + โœ” Confirm deploy to network polkadotTestnet (420420420)? โ€ฆ yes +   + Hardhat Ignition ๐Ÿš€ +   + Deploying [ MyNFTModule ] +   + Batch #1 + Executed MyNFTModule#MyNFT +   + Batch #2 + Executed MyNFTModule#MyNFT.safeMint +   + [ TokenModule ] successfully deployed ๐Ÿš€ +   + Deployed Addresses +   + MyNFTModule#MyNFT - 0x1234....... + +
\ No newline at end of file diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/hardhat.config.ts b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/hardhat.config.ts new file mode 100644 index 000000000..1877f91a8 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/hardhat.config.ts @@ -0,0 +1,48 @@ +import type { HardhatUserConfig } from 'hardhat/config'; + +import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; +import { configVariable } from 'hardhat/config'; + +const config: HardhatUserConfig = { + plugins: [hardhatToolboxViemPlugin], + solidity: { + profiles: { + default: { + version: '0.8.28', + }, + production: { + version: '0.8.28', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + }, + }, + networks: { + hardhatMainnet: { + type: 'edr-simulated', + chainType: 'l1', + }, + hardhatOp: { + type: 'edr-simulated', + chainType: 'op', + }, + sepolia: { + type: 'http', + chainType: 'l1', + url: configVariable('SEPOLIA_RPC_URL'), + accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], + }, + polkadotHubTestnet: { + type: 'http', + url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', + chainId: 420420422, + accounts: [configVariable('PRIVATE_KEY')], + }, + }, +}; + +export default config; \ No newline at end of file diff --git a/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/MyNFT.sol b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/MyNFT.sol new file mode 100644 index 000000000..0bcab0501 --- /dev/null +++ b/.snippets/code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/MyNFT.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; + +contract MyNFT is ERC721, Ownable { + uint256 private _nextTokenId; + + constructor( + address initialOwner + ) ERC721("MyToken", "MTK") Ownable(initialOwner) {} + + function safeMint(address to) public onlyOwner { + uint256 tokenId = _nextTokenId++; + _safeMint(to, tokenId); + } +} diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-1.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-1.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-1.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-1.webp diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-2.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-2.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-2.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-2.webp diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-3.gif b/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-3.gif similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-3.gif rename to images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-3.gif diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-4.gif b/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-4.gif similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-4.gif rename to images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-4.gif diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-5.gif b/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-5.gif similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-5.gif rename to images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-5.gif diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-01.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-01.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-01.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-01.webp diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-02.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-02.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-02.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-02.webp diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-03.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-03.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-03.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-03.webp diff --git a/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-04.webp b/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-04.webp similarity index 100% rename from images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-04.webp rename to images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-04.webp diff --git a/smart-contracts/cookbook/.nav.yml b/smart-contracts/cookbook/.nav.yml index 967a352ff..34648a128 100644 --- a/smart-contracts/cookbook/.nav.yml +++ b/smart-contracts/cookbook/.nav.yml @@ -1,5 +1,5 @@ nav: -- 'Overview': index.md # TODO: Update name of page +- 'Overview': index.md - 'Get Tokens from the Faucet': /smart-contracts/faucet/ - 'EVM Smart Contracts': smart-contracts - 'Create a DApp': dapps diff --git a/smart-contracts/cookbook/dapps/zero-to-hero.md b/smart-contracts/cookbook/dapps/zero-to-hero.md index d45dc3a05..591380895 100644 --- a/smart-contracts/cookbook/dapps/zero-to-hero.md +++ b/smart-contracts/cookbook/dapps/zero-to-hero.md @@ -352,7 +352,7 @@ This file defines the contract address, ABI, and functions to create a viem [con ## Create the Wallet Connection Component -Now, let's create a component to handle wallet connections. Create a new file called `components/WalletConnect.tsx`: +Now, you can create a component to handle wallet connections. Create a new file called `components/WalletConnect.tsx`: ```typescript title="WalletConnect.tsx" "use client"; @@ -535,7 +535,7 @@ This component handles connecting to the wallet, switching networks if necessary ## Create the Read Contract Component -Now, let's create a component to read data from the contract. Create a file called `components/ReadContract.tsx`: +Next, create a component to read data from the contract. Create a file called `components/ReadContract.tsx`: ```typescript title="ReadContract.tsx" 'use client'; @@ -608,7 +608,7 @@ This component reads the `storedNumber` value from the contract and displays it ## Create the Write Contract Component -Finally, let's create a component that allows users to update the stored number. Create a file called `components/WriteContract.tsx`: +Finally, create a component that allows users to update the stored number. Create a file called `components/WriteContract.tsx`: ```typescript title="WriteContract.tsx" "use client"; diff --git a/smart-contracts/cookbook/eth-dapps/uniswap-v2.md b/smart-contracts/cookbook/eth-dapps/uniswap-v2.md index c4bb1c79c..ef1ea1131 100644 --- a/smart-contracts/cookbook/eth-dapps/uniswap-v2.md +++ b/smart-contracts/cookbook/eth-dapps/uniswap-v2.md @@ -28,7 +28,7 @@ Before starting, make sure you have: ## Set Up the Project -Let's start by cloning the Uniswap V2 project: +Start by cloning the Uniswap V2 project: 1. Clone the Uniswap V2 repository: diff --git a/smart-contracts/cookbook/index.md b/smart-contracts/cookbook/index.md index 3245654d9..7586ecbee 100644 --- a/smart-contracts/cookbook/index.md +++ b/smart-contracts/cookbook/index.md @@ -1,5 +1,5 @@ --- -title: Smart Contracts Cookbook Index +title: Smart Contracts Cookbook description: Explore our full collection of tutorials and guides to learn step-by-step how to build, deploy, and work with smart contracts on Polkadot. categories: Basics, dApps, Smart Contracts --- diff --git a/smart-contracts/cookbook/smart-contracts/.nav.yml b/smart-contracts/cookbook/smart-contracts/.nav.yml index d1235a445..0aaa313cc 100644 --- a/smart-contracts/cookbook/smart-contracts/.nav.yml +++ b/smart-contracts/cookbook/smart-contracts/.nav.yml @@ -1,4 +1,4 @@ nav: - 'Deploy a Basic Contract': deploy-basic -- 'Deploy an ERC-20': deploy-erc20 -- 'Deploy an NFT': deploy-nft +- 'Deploy an ERC-20 Token': deploy-erc20 +- 'Deploy an ERC-721 NFT': deploy-nft diff --git a/smart-contracts/cookbook/smart-contracts/deploy-basic/.nav.yml b/smart-contracts/cookbook/smart-contracts/deploy-basic/.nav.yml index 65e5ee766..0d5583479 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-basic/.nav.yml +++ b/smart-contracts/cookbook/smart-contracts/deploy-basic/.nav.yml @@ -1,4 +1,4 @@ nav: - - 'Using Remix IDE': remix.md - - 'Using Hardhat': hardhat.md + - 'Remix IDE': basic-remix.md + - 'Hardhat': basic-hardhat.md # - 'Using Foundry': foundry.md diff --git a/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat.md new file mode 100644 index 000000000..b585bbb5a --- /dev/null +++ b/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat.md @@ -0,0 +1,114 @@ +--- +title: Deploy a Basic Contract with Hardhat +description: Learn how to deploy a basic smart contract to Polkadot Hub using Hardhat, ideal for professional workflows that require comprehensive testing and debugging. +categories: Smart Contracts +--- + +# Deploy a Basic Contract with Hardhat + +## Introduction + +This guide demonstrates how to deploy a basic Solidity smart contract to Polkadot Hub TestNet using [Hardhat](https://hardhat.org/){target=\_blank}, which provides a comprehensive development environment with built-in testing, debugging, and deployment capabilities. It's ideal for professional development workflows and team projects. + +## Prerequisites + +Before you begin, ensure you have the following: + +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming. +- [Node.js](https://nodejs.org/en/download){target=\_blank} v22.13.1 or later installed. +- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. +- A wallet with a private key for signing transactions. + +## Set Up Your Project + +Use the following terminal commands to create a directory and initialize your Hardhat project inside of it: + +```bash +mkdir hardhat-deployment +cd hardhat-deployment +npx hardhat --init +``` + +## Configure Hardhat + +Open `hardhat.config.ts` and update to add `polkadotHubTestnet` to the `networks` configuration as highlighted in the following example code: + +```typescript title='hardhat.config.ts' hl_lines='39-43' +--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/hardhat.config.ts' +``` + +!!! tip + Visit the Hardhat [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} documentation to learn how to use Hardhat to handle your private keys securely. + +## Create the Contract + +Follow these steps to create your smart contract: + +1. Delete the default contract file(s) in the `contracts` directory. + +2. Create a new file named `Storage.sol` inside the `contracts` directory. + +3. Add the following code to create the `Storage.sol` smart contract: + ```solidity title="Storage.sol" + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/Storage.sol' + ``` + +## Compile the Contract + +Compile your `Storage.sol` contract using the following command: + +```bash +npx hardhat compile +``` + +You will see a message in the terminal confirming the contract was successfully compiled, similar to the following: + +--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/compile-output.html' + +## Deploy the Contract + +You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows: + +1. Delete the default file(s) inside the `ignition/modules` directory. + +2. Create a new file named `Storage.ts` inside the `ignition/modules` directory. + +3. Open `ignition/modules/Storage.ts` and add the following code to create your deployment module: + + ```typescript title="ignition/modules/Storage.ts" + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/storage.ts' + ``` + +4. Deploy your contract to Polkadot Hub TestNet using the following command: + + ```bash + npx hardhat ignition deploy ignition/modules/Storage.ts --network polkadotHubTestnet + ``` + +5. Confirm the target deployment network name and chain ID when prompted: + + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-hardhat/deploy-output.html' + +Congratulations! You've now deployed a basic smart contract to Polkadot Hub TestNet using Hardhat. Consider the following resources to build upon your progress. + +## Where to Go Next + +
+ +- Guide __Deploy an ERC-20__ + + --- + + Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/) + +- Guide __Deploy an NFT__ + + --- + + Walk through deploying an NFT to the Polkadot Hub using Hardhat. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/) + +
\ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-remix.md b/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-remix.md new file mode 100644 index 000000000..ca65761d5 --- /dev/null +++ b/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-remix.md @@ -0,0 +1,80 @@ +--- +title: Deploy a Basic Contract with Remix IDE +description: Learn how to deploy a basic smart contract to Polkadot Hub using Remix IDE, ideal for rapid prototyping, learning, and visual development. +categories: Smart Contracts +--- + +# Deploy a Basic Contract with Remix IDE + +## Introduction + +This guide demonstrates how to deploy a basic Solidity smart contract to Polkadot Hub using [Remix IDE](https://remix.ethereum.org/){target=\_blank}, which offers a visual, browser-based environment perfect for rapid prototyping and learning. It requires no local installation and provides an intuitive interface for contract development. + +## Prerequisites + +Before you begin, ensure you have the following: + +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming. +- An EVM-compatible [wallet](/smart-contracts/connect/){target=\_blank} connected to Polkadot Hub. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. +- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. + +## Locate Your Contract + +This guide uses a default contract contract provided by Remix IDE. Follow these steps to locate the contract in Remix: + +1. Navigate to [Remix IDE](https://remix.ethereum.org/){target=\_blank} in your web browser. + +2. Once the default workspace loads, locate the `contracts` folder. Inside `contracts`, locate the `Storage.sol` file which you will use as your sample contract throughout this guide. + +![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/basic-remix/basic-remix-01.webp) + +## Compile the Contract + +Solidity source code compiles into bytecode that can be deployed on the blockchain. During this process, the compiler checks the contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. + +Ensure your `Storage.sol` contract is open in the Remix IDE editor, and use the following steps to compile: + +1. Select the **Solidity Compiler** plugin from the left panel. +2. Select the **Compile Storage.sol** button. + +The **Solidity Compiler** icon will display a green checkmark once the contract compiles successfully. If any issues arise during contract compilation, errors and warnings will appear in the terminal panel at the bottom of the screen. + +![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-02.webp) + +## Deploy the Contract + +Follow these steps to deploy the contract using Remix: + +1. Select **Deploy & Run Transactions** from the left panel. +2. Ensure your MetaMask wallet is connected to Polkadot Hub TestNet, then select the **Environment** dropdown and select **Injected Provider - MetaMask**. +3. Select the **Deploy** button to initiate the deployment. +4. Approve the transaction in your MetaMask wallet when prompted. +5. You will see the transaction details in the terminal when the deployment succeeds, including the contract address and deployment transaction hash. + +![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-03.webp) + +Once successfully deployed, your contract will appear in the **Deployed Contracts** section, ready for interaction. + +Congratulations! You've successfully deployed a basic smart contract to Polkadot Hub TestNet using Remix IDE. Consider the following resources to build upon your progress. + +## Where to Go Next + +
+ +- Guide __Deploy an ERC-20__ + + --- + + Walk through deploying a fully-functional ERC-20 to Polkadot Hub using Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/) + +- Guide __Deploy an NFT__ + + --- + + Walk through deploying an NFT to Polkadot Hub using Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/) + +
\ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat.md deleted file mode 100644 index f9255021b..000000000 --- a/smart-contracts/cookbook/smart-contracts/deploy-basic/hardhat.md +++ /dev/null @@ -1,164 +0,0 @@ ---- -title: Deploy a Basic Contract with Hardhat -description: Learn how to deploy a basic smart contract to Polkadot Hub using Hardhat, Perfect for professional workflows requiring comprehensive testing and debugging. -categories: Smart Contracts ---- - -# Deploy a Basic Contract with - -## Introduction - -This guide demonstrates how to deploy a basic Solidity smart contract to Polkadot Hub using [Hardhat](https://hardhat.org/){target=\_blank}, which provides a comprehensive development environment with built-in testing, debugging, and deployment capabilities. It's ideal for professional development workflows and team projects. - -## Prerequisites - -- Basic understanding of Solidity programming. -- [Node.js](https://nodejs.org/en/download){target=\_blank} v22.13.1 or later. -- Test tokens for gas fees (available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}). See the [step-by-step instructions](/smart-contracts/faucet/#get-test-tokens){target=\_blank}. -- A wallet with a private key for signing transactions. - -## Set Up Your Project - -Initialize your Hardhat project: - -```bash -mkdir hardhat-deployment -cd hardhat-deployment -npx hardhat --init -``` - -## Configure Hardhat - -Edit `hardhat.config.js`: - -```javascript title='hardhat.config.js' hl_lines='39-43' -import type { HardhatUserConfig } from 'hardhat/config'; - -import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; -import { configVariable } from 'hardhat/config'; - -const config: HardhatUserConfig = { - plugins: [hardhatToolboxViemPlugin], - solidity: { - profiles: { - default: { - version: '0.8.28', - }, - production: { - version: '0.8.28', - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, - }, - }, - networks: { - hardhatMainnet: { - type: 'edr-simulated', - chainType: 'l1', - }, - hardhatOp: { - type: 'edr-simulated', - chainType: 'op', - }, - sepolia: { - type: 'http', - chainType: 'l1', - url: configVariable('SEPOLIA_RPC_URL'), - accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], - }, - polkadotHubTestnet: { - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - chainId: 420420422, - accounts: [configVariable('PRIVATE_KEY')], - }, - }, -}; - -export default config; - -``` - -!!! tip - Learn how to use Hardhat's [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} to handle your private keys in a secure way. - -## Create Your Contract - -Replace the default contract in `contracts/Storage.sol`: - -```solidity -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.9; - -contract Storage { - uint256 private storedNumber; - - function store(uint256 num) public { - storedNumber = num; - } - - function retrieve() public view returns (uint256) { - return storedNumber; - } -} -``` - -## Compile - -```bash -npx hardhat build -``` - -## Set Up Deployment - -Create a deployment module in `ignition/modules/Storage.ts`: - -```typescript title="ignition/modules/Storage.ts" -import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; - -export default buildModule('StorageModule', (m) => { - const storage = m.contract('Storage'); - return { storage }; -}); -``` - -## Deploy the Contract - -Deploy to Polkadot Hub TestNet: - -```bash -npx hardhat ignition deploy ignition/modules/Storage.ts --network polkadotHubTestnet -``` - -## Where to Go Next - -
- -- Guide __Verify Your Contract__ - - --- - - Now that you've deployed a basic contract, learn how to verify it with Hardhat. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/hardhat/verify-a-contract/) - -- Guide __Deploy an ERC-20__ - - --- - - Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/hardhat/) - -- Guide __Deploy an NFT__ - - --- - - Walk through deploying a NFT to the Polkadot Hub using Hardhat. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat/) - -
\ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-basic/remix.md b/smart-contracts/cookbook/smart-contracts/deploy-basic/remix.md deleted file mode 100644 index 2618936b9..000000000 --- a/smart-contracts/cookbook/smart-contracts/deploy-basic/remix.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: Deploy a Basic Contract with Remix IDE -description: Learn how to deploy a basic smart contract to Polkadot Hub using Remix IDE Ideal for rapid prototyping, learning, and visual development. -categories: Smart Contracts ---- - -# Deploy a Basic Contract with Remix IDE - -## Introduction - -This guide demonstrates how to deploy a basic Solidity smart contract to Polkadot Hub using [Remix IDE](https://remix.ethereum.org/){target=\_blank}, which offers a visual, browser-based environment perfect for rapid prototyping and learning. It requires no local installation and provides an intuitive interface for contract development. - -## Prerequisites - -- Basic understanding of Solidity programming. -- Test tokens for gas fees (available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}). See the [step-by-step instructions](/smart-contracts/faucet/#get-test-tokens){target=\_blank}. -- A wallet with a private key for signing transactions. - -## Access Remix - -Navigate to [Remix](https://remix.ethereum.org/){target=\_blank} in your web browser. - -The interface will load with a default workspace containing sample contracts. In this interface, you can access a file explorer, edit your code, interact with various plugins for development, and use a terminal. By default, you will see the `contracts` folder with the `Storage.sol` file, which will be used as the example contract throughout this guide. - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-01.webp) - -## Compile - -1. Navigate to the **Solidity Compiler** tab, which is the third icon in the left sidebar. -2. Click **Compile Storage.sol** or press `Ctrl+S`. - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-02.webp) - -Compilation errors and warnings appear in the terminal panel at the bottom of the screen. - -## Deploy - -1. Navigate to the **Deploy & Run Transactions** tab. -2. Click the **Environment** dropdown and select **Injected Provider - MetaMask** (ensure your MetaMask wallet is connected to Polkadot Hub TestNet). -3. Click **Deploy**. -4. Approve the transaction in your MetaMask wallet. - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-basic/deploy-basic/deploy-basic-03.webp) - -Your deployed contract will appear in the **Deployed Contracts** section, ready for interaction. - -## Where to Go Next - -
- -- Guide __Verify Your Contract__ - - --- - - Now that you've deployed a basic contract, learn how to verify it with Remix. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/remix/verify-a-contract/) - -- Guide __Deploy an ERC-20__ - - --- - - Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Remix. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/remix/) - -- Guide __Deploy an NFT__ - - --- - - Walk through deploying a NFT to the Polkadot Hub using Remix. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) - -
\ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-erc20/.nav.yml b/smart-contracts/cookbook/smart-contracts/deploy-erc20/.nav.yml index 377ab7153..0e8ca6a78 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-erc20/.nav.yml +++ b/smart-contracts/cookbook/smart-contracts/deploy-erc20/.nav.yml @@ -1,5 +1,4 @@ -title: Deploy an ERC-20 nav: -- 'Remix': erc20-remix.md +- 'Remix IDE': erc20-remix.md - 'Hardhat': erc20-hardhat.md # - 'Foundry': erc20-foundry.md \ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md index 04ded0978..430a7a383 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md +++ b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat.md @@ -1,30 +1,33 @@ --- -title: Deploy an ERC-20 to Polkadot Hub +title: Deploy an ERC-20 Using Hardhat description: Deploy an ERC-20 token on Polkadot Hub using PolkaVM. This guide covers contract creation, compilation, deployment, and interaction via Hardhat. tutorial_badge: Intermediate categories: Basics, Smart Contracts tools: Hardhat --- -# Deploy an ERC-20 to Polkadot Hub +# Deploy an ERC-20 Using Hardhat ## Introduction -[ERC-20](https://eips.ethereum.org/EIPS/eip-20){target=\_blank} tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy token deployment with Ethereum-compatible smart contracts and tools via the EVM backend. +[ERC-20](https://eips.ethereum.org/EIPS/eip-20){target=\_blank} tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy deployment of ERC-20 tokens via Ethereum-compatible smart contracts and tools. -This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Hardhat](https://hardhat.org/){target=\_blank}, an Ethereum development environment. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}. +This guide demonstrates how to deploy an ERC-20 contract on Polkadot Hub TestNet using [Hardhat](https://hardhat.org/){target=\_blank}, an Ethereum development environment. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}. ## Prerequisites -Before starting, make sure you have: +Before you begin, ensure you have the following: -- Basic understanding of Solidity programming and fungible tokens. -- Node.js v22.13.1 or later. -- A funded account with tokens for transaction fees. This example will deploy the contract to the Polkadot TestNet, so you'll [need some TestNet tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}. +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming and [ERC-20](https://ethereum.org/developers/docs/standards/tokens/erc-20/){target=\_blank} fungible tokens. +- [Node.js](https://nodejs.org/en/download){target=\_blank} v22.13.1 or later installed. +- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. +- A wallet with a private key for signing transactions. ## Set Up Your Project -This tutorial uses a [Hardhat ERC-20 template](https://github.com/polkadot-developers/revm-hardhat-examples/tree/master/erc20-hardhat){target=\_blank} that contains all the necessary files. To get started, take the following steps: +This tutorial uses a [Hardhat ERC-20 template](https://github.com/polkadot-developers/revm-hardhat-examples/tree/master/erc20-hardhat){target=\_blank} that contains all the necessary files. + +To get started, take the following steps: 1. Clone the GitHub repository locally: @@ -33,134 +36,75 @@ This tutorial uses a [Hardhat ERC-20 template](https://github.com/polkadot-devel cd revm-hardhat-examples/erc20-hardhat ``` -2. Install the dependencies: +2. Install the dependencies using the following command: ```bash npm i ``` - -This will fetch all the necessary packages to help you deploy an ERC-20 with Hardhat to Polkadot. + + This command will fetch all the necessary packages to help you use Hardhat to deploy an ERC-20 to Polkadot. ## Configure Hardhat -Once you've [setup your project](#set-up-your-project), you can configure the `hardhat.config.ts` to your needs. This tutorial has the file prepared to deploy to the Polkadot TestNet. - -To store and use private keys or network URLs, you can use Hardhat's configuration variables. This can be set via tasks in the **vars** scope. For example, to store the private key to deploy to the Polkadot TestNet, run the following command: - -```bash -npx hardhat vars set TESTNET_PRIVATE_KEY -``` - -The command will initiate a wizard in which you'll have to enter the value to be stored: +If you started with the cloned Hardhat ERC-20 template, `hardhat.config.ts` is already configured to deploy to the Polkadot TestNet as shown in the example below: -
- npx hardhat vars set TESTNET_PRIVATE_KEY - โœ” Enter value: ยท โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข - The configuration variable has been stored in /Users/albertoviera/Library/Preferences/hardhat-nodejs/vars.json -
- -??? warning "Key Encryption" - This solution just prevents variables to be included in the code repository. You should find a solution that encrypts private keys and access them securely. - -You can now use the account related to this private key by importing it into the Hardhat configuration file: - -```ts title="hardhat.config.ts" hl_lines="1 17" +```ts title="hardhat.config.ts" hl_lines="14-19" --8<-- "https://raw.githubusercontent.com/polkadot-developers/revm-hardhat-examples/refs/heads/master/erc20-hardhat/hardhat.config.ts::2" --8<-- "https://raw.githubusercontent.com/polkadot-developers/revm-hardhat-examples/refs/heads/master/erc20-hardhat/hardhat.config.ts:24:45" ``` -## Compile your Contract +!!! tip + Visit the Hardhat [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} documentation to learn how to use Hardhat to handle your private keys securely. -Once you've configured Hardhat, you can compile the contract. +## Compile the Contract -In this tutorial, a simple ERC-20 is provided. Therefore, to compile the contract you can run the following command: +Next, compile the contract included with the template by running the following command: ```bash npx hardhat compile ``` -If everything compiles successfully, you should see the following output: +If everything compiles successfully, you will see output similar to the following: -
- npx hardhat compile - Generating typings for: 23 artifacts in dir: typechain-types for target: ethers-v6 - Successfully generated 62 typings! - Compiled 21 Solidity files successfully (evm target: paris). -
+--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-erc20-token/erc20-hardhat/compile-output.html' -## Test your Contract -Hardhat has a native feature to test contracts. You can run tests against the local Hardhat development node, but it could have some technical differences to Polkadot. Therefore, in this tutorial, you'll be testing against the Polkadot TestNet +## Test the Contract -This example has a predefined test file located in [`test/Token.test.js`](https://github.com/polkadot-developers/revm-hardhat-examples/blob/master/erc20-hardhat/test/MyToken.test.ts){target=\_blank}, that runs the following tests: +You can view the predefined test file at [`test/MyToken.test.ts`](https://github.com/polkadot-developers/revm-hardhat-examples/blob/master/erc20-hardhat/test/MyToken.test.ts){target=\_blank}. This example test includes verification of the following: -1. The token was deployed by verifying its **name** and **symbol**. -2. The token has the right owner configured. -3. The token has an initial supply of zero. -4. The owner can mint tokens. -5. The total supply is increased after a mint. -6. Perform multiple mints to different addresses and checks the balance of each address and the new total supply. +- The token name and symbol exist (confirms deployment) and are correct. +- The token owner is correctly configured. +- The initial token supply is zero. +- The owner can mint tokens. +- The total supply increases after a mint. +- Successful mints to different test addresses with expected account balance and total supply changes. -To run the test, you can execute the following command: +Run the tests using the following command: ```bash npx hardhat test --network polkadotTestnet ``` -If tests are successful, you should see the following logs: +If tests are successful, you will see outputs similar to the following: -
- npx hardhat test --network polkadotTestnet - -   MyToken -     Deployment -       โœ” Should have correct name and symbol -       โœ” Should set the right owner -       โœ” Should have zero initial supply -     Minting -       โœ” Should allow owner to mint tokens -       โœ” Should increase total supply on mint -     Multiple mints -       โœ” Should correctly track balance after multiple mints - -   6 passing (369ms) -
+--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/testing-output.html' -## Deploy your Contract +## Deploy the Contract -With the Hardhat configuration file ready, the private key stored as a variable under **vars**, and the contract compiled, you can proceed to deploy the contract to a given network. In this tutorial, you are deploying it to the Polkadot TestNet. +You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows: -To deploy the contract, run the following command: +1. Run the following command in your terminal: + ```bash + npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet + ``` -```bash -npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet -``` +2. Confirm the target deployment network name and chain ID when prompted: + + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/deploy-output.html' -You'll need to confirm the target network (by chain ID): - -
- npx hardhat ignition deploy ./ignition/modules/MyToken.ts --network polkadotTestnet - โœ” Confirm deploy to network polkadotTestnet (420420420)? โ€ฆ yes -   - Hardhat Ignition ๐Ÿš€ -   - Deploying [ TokenModule ] -   - Batch #1 - Executed TokenModule#MyToken -   - Batch #2 - Executed TokenModule#MyToken.mint -   - [ TokenModule ] successfully deployed ๐Ÿš€ -   - Deployed Addresses -   - TokenModule#MyToken - 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3 -
- -And that is it! You've successfully deployed an ERC-20 token contract to the Polkadot TestNet using Hardhat. +Congratulations! You've successfully deployed an ERC-20 token contract to Polkadot Hub TestNet using Hardhat. Consider the following resources to build upon your progress. ## Where to Go Next @@ -172,6 +116,6 @@ And that is it! You've successfully deployed an ERC-20 token contract to the Pol Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/) \ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md index 48da3e2a3..d92da4761 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md +++ b/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix.md @@ -1,125 +1,88 @@ --- -title: Deploy an ERC-20 to Polkadot Hub +title: Deploy an ERC-20 Using Remix IDE description: Deploy an ERC-20 token contract on Polkadot Hub. This guide covers contract creation, compilation, deployment, and interaction via the Remix IDE. tutorial_badge: Beginner categories: Basics, Smart Contracts tools: EVM Wallet, Remix --- -# Deploy an ERC-20 to Polkadot Hub +# Deploy an ERC-20 Using Remix IDE ## Introduction [ERC-20](https://eips.ethereum.org/EIPS/eip-20){target=\_blank} tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Polkadot Hub enables easy token deployment with Ethereum-compatible smart contracts and tools via the EVM backend. -This tutorial covers deploying an ERC-20 contract on the Polkadot Hub TestNet using [Remix IDE](https://remix.ethereum.org/){target=\_blank}, a web-based development tool. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}. +This tutorial covers deploying an ERC-20 contract on Polkadot Hub TestNet using [Remix IDE](https://remix.ethereum.org/){target=\_blank}, a web-based development tool. The ERC-20 contract can be retrieved from OpenZeppelin's [GitHub repository]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20){target=\_blank} or their [Contract Wizard](https://wizard.openzeppelin.com/){target=\_blank}. ## Prerequisites -Before starting, make sure you have: +Before you begin, ensure you have: -- Basic understanding of Solidity programming and fungible tokens. -- An EVM-compatible wallet [connected to Polkadot Hub](/smart-contracts/integrations/wallets){target=\_blank}. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. -- A funded account with tokens for transaction fees. This example will deploy the contract to the Polkadot TestNet, so you'll [need some TestNet tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}. +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming and [ERC-20](https://ethereum.org/developers/docs/standards/tokens/erc-20/){target=\_blank} fungible tokens. +- An EVM-compatible [wallet](/smart-contracts/connect/){target=\_blank} connected to Polkadot Hub. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. +- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. ## Create Your Contract -To create the ERC-20 contract, you can follow the steps below: +Follow the steps below to create the ERC-20 contract: -1. Navigate to the [Polkadot Remix IDE](https://remix.polkadot.io){target=\_blank}. -2. Click in the **Create new file** button under the **contracts** folder, and name your contract as `MyToken.sol`. +1. Navigate to [Remix IDE](https://remix.ethereum.org/){target=\_blank} in your web browser. +2. Select the **Create new file** button under the **contracts** folder, and name your contract `MyToken.sol`. - ![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-1.webp) + ![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-1.webp) -3. Now, paste the following ERC-20 contract code into the editor: +3. Now, paste the following ERC-20 contract code into `MyToken.sol`: ```solidity title="MyToken.sol" --8<-- 'https://raw.githubusercontent.com/polkadot-developers/revm-hardhat-examples/refs/heads/master/erc20-hardhat/contracts/MyToken.sol' ``` - - The key components of the code above are: - - - Contract imports: - - - **[`ERC20.sol`]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20/ERC20.sol){target=\_blank}**: The base contract for fungible tokens, implementing core functionality like transfers, approvals, and balance tracking. - - **[`ERC20Permit.sol`]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/token/ERC20/extensions/ERC20Permit.sol){target=\_blank}**: [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612){target=\_blank} extension for ERC-20 that adds the [permit function](https://docs.openzeppelin.com/contracts/5.x/api/token/erc20#ERC20Permit-permit-address-address-uint256-uint256-uint8-bytes32-bytes32-){target=\_blank}, allowing approvals via off-chain signatures (no on-chain tx from the holder). Manages nonces and EIP-712 domain separator and updates allowances when a valid signature is presented. - - **[`Ownable.sol`]({{ dependencies.repositories.open_zeppelin_contracts.repository_url}}/tree/{{ dependencies.repositories.open_zeppelin_contracts.version}}/contracts/access/Ownable.sol){target=\_blank}**: Provides basic authorization control, ensuring only the contract owner can mint new tokens. - - Constructor parameters: - - - **`initialOwner`**: Sets the address that will have administrative rights over the contract. - - **`"MyToken"`**: The full name of your token. - - **`"MTK"`**: The symbol representing your token in wallets and exchanges. - - - Key functions: - - - **`mint(address to, uint256 amount)`**: Allows the contract owner to create new tokens for any address. The amount should include 18 decimals (e.g., 1 token = 1000000000000000000). - - Inherited [Standard ERC-20](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/){target=\_blank} functions: - - **`transfer(address recipient, uint256 amount)`**: Sends a specified amount of tokens to another address. - - **`approve(address spender, uint256 amount)`**: Grants permission for another address to spend a specific number of tokens on behalf of the token owner. - - **`transferFrom(address sender, address recipient, uint256 amount)`**: Transfers tokens from one address to another, if previously approved. - - **`balanceOf(address account)`**: Returns the token balance of a specific address. - - **`allowance(address owner, address spender)`**: Checks how many tokens an address is allowed to spend on behalf of another address. - !!! tip - 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 the Remix IDE for deployment. Below is an example of an ERC-20 token contract created with it: - - ![Screenshot of the OpenZeppelin Contracts Wizard showing an ERC-20 contract configuration.](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-2.webp) + The [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\_blank} was used to generate this example ERC-20 contract. +## Compile the Contract -## Compile - -The compilation transforms your Solidity source code into bytecode that can be deployed on the blockchain. During this process, the compiler checks your contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. +Solidity source code compiles into bytecode that can be deployed on the blockchain. During this process, the compiler checks the contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. -To compile your contract, ensure you have it opened in the Remix IDE Editor, and follow the instructions below: +Ensure your `MyToken.sol` contract is open in the Remix IDE Editor, and use the following steps to compile: 1. Select the **Solidity Compiler** plugin from the left panel. -2. Click the **Compile MyToken.sol** button. -3. If the compilation succeeded, you'll see a green checkmark indicating success in the **Solidity Compiler** icon. - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-3.gif) - -## Deploy - -Deployment is the process of publishing your compiled smart contract to the blockchain, making it permanently available for interaction. During deployment, you'll create a new instance of your contract on the blockchain, which involves: - -1. Select the **Deploy & Run Transactions** plugin from the left panel. -2. Configure the deployment settings: - 1. From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (check the [Deploying Contracts](/smart-contracts/dev-environments/remix/deploy-a-contract/){target=\_blank} section of the Remix IDE guide for more details). - 2. (Optional) From the **ACCOUNT** dropdown, select the acccount you want to use for the deploy. - -3. Configure the contract parameters: - 1. Enter the address that will own the deployed token contract. - 2. Click the **Deploy** button to initiate the deployment. +2. Select the **Compile MyToken.sol** button. -4. **MetaMask will pop up**: Review the transaction details. Click **Confirm** to deploy your contract. -5. If the deployment process succeeded, you will see the transaction details in the terminal, including the contract address and deployment transaction hash. +The **Solidity Compiler** icon will display a green checkmark once the contract compiles successfully. If any issues arise during contract compilation, errors and warnings will appear in the terminal panel at the bottom of the screen. -![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-4.gif) +![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-3.gif) -## Interact with Your Contract +## Deploy the Contract -Once deployed, you can interact with your contract through Remix. Find your contract under **Deployed/Unpinned Contracts**, and click it to expand the available methods. In this example, you'll mint some tokens to a given address: +Follow these steps to deploy the contract using Remix: -1. Expand the **mint** function: - 1. Enter the recipient address and the amount (remember to add 18 zeros for 1 whole token). - 2. Click **transact**. +1. Select **Deploy & Run Transactions** from the left panel. +2. Ensure your MetaMask wallet is connected to Polkadot Hub TestNet, then select the **Environment** dropdown and select **Injected Provider - MetaMask**. +3. Configure the contract parameters by entering the address that will own the deployed token contract. +4. Select the **Deploy** button to initiate the deployment. +4. Approve the transaction in your MetaMask wallet when prompted. +6. You will see the transaction details in the terminal when the deployment succeeds, including the contract address and deployment transaction hash. -2. Click **Approve** to confirm the transaction in the MetaMask popup. +![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-4.gif) -3. If the transaction succeeds, you will see a green check mark in the terminal. +Once successfully deployed, your contract will appear in the **Deployed Contracts** section, ready for interaction. -4. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance. +## Interact with the Contract -![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix-5.gif) +Once deployed, you can interact with your contract through Remix. Find your contract under **Deployed/Unpinned Contracts**, and select it to expand the available methods. In this example, you'll mint some tokens to a given address using the following steps: +1. Expand the **mint** function, then enter the recipient address and the amount (remember to add 18 zeros for one whole token). +2. Select **transact**. +3. Approve the transaction in your MetaMask wallet when prompted. +4. You will see a green check mark in the terminal when the transaction is successful. +5. You can also call the **balanceOf** function by passing the address of the **mint** call to confirm the new balance. -Other standard functions you can use: +![](/images/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-remix/erc20-remix-5.gif) -- **`transfer(address to, uint256 amount)`**: Send tokens to another address. -- **`approve(address spender, uint256 amount)`**: Allow another address to spend your tokens. +Feel free to explore and interact with the contract's other functions by selecting the method, providing any required parameters, and confirming the transaction in MetaMask when prompted. -Feel free to explore and interact with the contract's other functions using the same approach: select the method, provide any required parameters, and confirm the transaction in MetaMask when needed. +Congratulations! You've successfully deployed an ERC-20 token contract to Polkadot Hub TestNet using Remix IDE. Consider the following resources to build upon your progress. ## Where to Go Next @@ -131,6 +94,6 @@ Feel free to explore and interact with the contract's other functions using the Walk through deploying an ERC-721 Non-Fungible Token (NFT) using OpenZeppelin's battle-tested NFT implementation and Remix. - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/) + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/) \ No newline at end of file diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/.nav.yml b/smart-contracts/cookbook/smart-contracts/deploy-nft/.nav.yml index d4ecb3804..77633ec86 100644 --- a/smart-contracts/cookbook/smart-contracts/deploy-nft/.nav.yml +++ b/smart-contracts/cookbook/smart-contracts/deploy-nft/.nav.yml @@ -1,4 +1,4 @@ nav: -- 'Using Remix': remix.md -- 'Using Hardhat': hardhat.md +- 'Remix IDE': nft-remix.md +- 'Hardhat': nft-hardhat.md # - 'Using Foundry': foundry.md diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md deleted file mode 100644 index 22f09f8fb..000000000 --- a/smart-contracts/cookbook/smart-contracts/deploy-nft/hardhat.md +++ /dev/null @@ -1,177 +0,0 @@ ---- -title: Deploy an NFT to Polkadot Hub with Hardhat -description: Learn how to deploy an ERC-721 NFT contract to Polkadot Hub with Hardhat, a comprehenive development environment with built-in deployment capabilities. -tutorial_badge: Beginner -categories: Basics, Smart Contracts -tools: EVM Wallet, Hardhat ---- - -# Deploy an NFT with Hardhat - -## Introduction - -Non-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification. - -This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\_blank}. You'll use [OpenZeppelin's battle-tested NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\_blank} and [Hardhat](https://hardhat.org/docs/getting-started){target=\_blank}, a comprehensive development environment with built-in testing, debugging, and deployment capabilities. Hardhat uses standard Solidity compilation to generate EVM bytecode, making it fully compatible with Polkadot Hub's EVM environment. - -## Prerequisites - -- Basic understanding of Solidity programming and NFT standards. -- Node.js v22.13.1 or later. -- A funded account with tokens for transaction fees. This example will deploy the contract to the Polkadot TestNet, so you'll [need some TestNet tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} from the [Polkadot Faucet](https://faucet.polkadot.io/?parachain=1111){target=\_blank}. -- A wallet with a private key for signing transactions. - -## Set Up Your Project - -Take the following steps to get started: - -1. Initialize your Hardhat project: - - ```bash - mkdir hardhat-nft-deployment - cd hardhat-nft-deployment - npx hardhat --init - ``` - -2. Install OpenZeppelin contracts: - - ```bash - npm install @openzeppelin/contracts - ``` - -## Configure Hardhat - -Edit `hardhat.config.ts`: - -```typescript title="hardhat.config.ts" -import type { HardhatUserConfig } from 'hardhat/config'; - -import hardhatToolboxViemPlugin from '@nomicfoundation/hardhat-toolbox-viem'; -import { configVariable } from 'hardhat/config'; - -const config: HardhatUserConfig = { - plugins: [hardhatToolboxViemPlugin], - solidity: { - profiles: { - default: { - version: '0.8.28', - }, - production: { - version: '0.8.28', - settings: { - optimizer: { - enabled: true, - runs: 200, - }, - }, - }, - }, - }, - networks: { - hardhatMainnet: { - type: 'edr-simulated', - chainType: 'l1', - }, - hardhatOp: { - type: 'edr-simulated', - chainType: 'op', - }, - sepolia: { - type: 'http', - chainType: 'l1', - url: configVariable('SEPOLIA_RPC_URL'), - accounts: [configVariable('SEPOLIA_PRIVATE_KEY')], - }, - polkadotHubTestnet: { - type: 'http', - url: 'https://testnet-passet-hub-eth-rpc.polkadot.io', - chainId: 420420422, - accounts: [configVariable('PRIVATE_KEY')], - }, - }, -}; - -export default config; -``` - -!!! tip - Learn how to use Hardhat's [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} to handle your private keys in a secure way. - -## Create Your Contract - -Create `contracts/MyNFT.sol`: - -```solidity title="contracts/MyNFT.sol" -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; - -import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; - -contract MyNFT is ERC721, Ownable { - uint256 private _nextTokenId; - - constructor(address initialOwner) - ERC721("MyToken", "MTK") - Ownable(initialOwner) - {} - - function safeMint(address to) public onlyOwner { - uint256 tokenId = _nextTokenId++; - _safeMint(to, tokenId); - } -} -``` - -## Compile - -```bash -npx hardhat compile -``` - -## Set Up Deployment - -Create a deployment module in `ignition/modules/MyNFT.ts`: - -```typescript title="ignition/modules/MyNFT.ts" -import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'; - -export default buildModule('MyNFTModule', (m) => { - const initialOwner = m.getParameter('initialOwner', 'INSERT_OWNER_ADDRESS'); - const myNFT = m.contract('MyNFT', [initialOwner]); - return { myNFT }; -}); -``` - -Replace `INSERT_OWNER_ADDRESS` with your desired owner address. - -## Deploy - -Deploy to Polkadot Hub TestNet: - -```bash -npx hardhat ignition deploy ignition/modules/MyNFT.ts --network polkadotHubTestnet -``` - -## Where to Go Next - -
- -- Guide __Verify Your Contract__ - - --- - - Now that you've deployed an NFT contract, learn how to verify it with Hardhat. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/hardhat/verify-a-contract/) - - -- Guide __Deploy an ERC-20__ - - --- - - Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Hardhat. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/hardhat/) - -
diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat.md b/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat.md new file mode 100644 index 000000000..f314c77d6 --- /dev/null +++ b/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat.md @@ -0,0 +1,117 @@ +--- +title: Deploy an ERC-721 Using Hardhat +description: Learn how to deploy an ERC-721 NFT contract to Polkadot Hub using Hardhat, a comprehensive development environment with built-in deployment capabilities. +tutorial_badge: Beginner +categories: Basics, Smart Contracts +tools: EVM Wallet, Hardhat +--- + +# Deploy an ERC-721 Using Hardhat + +## Introduction + +Non-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification. + +This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\_blank} TestNet. You'll use OpenZeppelin's battle-tested [NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\_blank} and [Hardhat](https://hardhat.org/docs/getting-started){target=\_blank}, a comprehensive development environment with built-in testing, debugging, and deployment capabilities. Hardhat uses standard Solidity compilation to generate EVM bytecode, making it fully compatible with Polkadot Hub's EVM environment. + +## Prerequisites + +Before you begin, ensure you have the following: + +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming and [ERC-721](https://ethereum.org/developers/docs/standards/tokens/erc-721/){target=\_blank} non-fungible tokens. +- [Node.js](https://nodejs.org/en/download){target=\_blank} v22.13.1 or later installed. +- Test tokens for gas fees, available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}. See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. +- A wallet with a private key for signing transactions. + +## Set Up Your Project + +1. Use the following terminal commands to create a directory and initialize your Hardhat project inside of it: + + ```bash + mkdir hardhat-nft-deployment + cd hardhat-nft-deployment + npx hardhat --init + ``` + +2. Install the OpenZeppelin contract dependencies using the command: + + ```bash + npm install @openzeppelin/contracts + ``` + +## Configure Hardhat + +Open `hardhat.config.ts` and update to add `polkadotHubTestnet` to the `networks` configuration as highlighted in the following example code: + +```typescript title="hardhat.config.ts" hl_lines='39-44' +--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/hardhat.config.ts' +``` + +!!! tip + Visit the Hardhat [Config Variables](https://hardhat.org/docs/learn-more/configuration-variables){target=\_blank} documentation to learn how to use Hardhat to handle your private keys securely. + +## Create the Contract + +Follow these steps to create your smart contract: + +1. Delete the default contract file(s) in the `contracts` directory. + +2. Create a new file named `MyNFT.sol` inside the `contracts` directory. + +3. Add the following code to create the `MyNFT.sol` smart contract: + ```solidity title="contracts/MyNFT.sol" + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.sol' + ``` + +## Compile the Contract + +Compile your `MyNFT.sol` contract using the following command: + +```bash +npx hardhat compile +``` + +You will see a message in the terminal confirming the contract was successfully compiled, similar to the following: + +--8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/compile-output.html' + +## Deploy the Contract + +You are now ready to deploy the contract to your chosen network. This example demonstrates deployment to the Polkadot TestNet. Deploy the contract as follows: + +1. Delete the default file(s) inside the `ignition/modules` directory. + +2. Create a new file named `MyNFT.ts` inside the `ignition/modules` directory. + +3. Open `ignition/modules/MyNFT.ts` and add the following code to create your deployment module: + ```typescript title="ignition/modules/MyNFT.ts" + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/MyNFT.ts' + ``` + + Replace `INSERT_OWNER_ADDRESS` with your desired owner address. + +4. Deploy your contract to Polkadot Hub TestNet using the following command: + + ```bash + npx hardhat ignition deploy ignition/modules/MyNFT.ts --network polkadotHubTestnet + ``` + +5. Confirm the target deployment network name and chain ID when prompted: + + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-hardhat/deploy-output.html' + +Congratulations! You've successfully deployed an ERC-721 NFT contract to Polkadot Hub TestNet using Hardhat. Consider the following resources to build upon your progress. + +## Where to Go Next + +
+ +- Guide __Deploy an ERC-20__ + + --- + + Walk through deploying a fully-functional ERC-20 to Polkadot Hub using Hardhat. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/erc20-hardhat/) + +
diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix.md b/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix.md new file mode 100644 index 000000000..c865070aa --- /dev/null +++ b/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix.md @@ -0,0 +1,86 @@ +--- +title: Deploy an ERC-721 NFT Using Remix +description: Learn how to deploy an ERC-721 NFT contract to Polkadot Hub using Remix, a browser-based IDE for quick prototyping and learning. +tutorial_badge: Beginner +categories: Basics, Smart Contracts +tools: Remix, EVM Wallet, OpenZeppelin +--- + +# Deploy an NFT with Remix + +## Introduction + +Non-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification. + +This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\_blank}. You'll use [OpenZeppelin's battle-tested NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\_blank} and [Remix](https://remix.ethereum.org/){target=\_blank}, a visual, browser-based environment perfect for rapid prototyping and learning. It requires no local installation and provides an intuitive interface for contract development. + +## Prerequisites + +- A basic understanding of [Solidity](https://www.soliditylang.org/){target=\_blank} programming and [ERC-721 NFT](https://ethereum.org/developers/docs/standards/tokens/erc-721/) standards. +- An EVM-compatible [wallet](/smart-contracts/connect/){target=\_blank} connected to Polkadot Hub. This example utilizes [MetaMask](https://metamask.io/){target=\_blank}. +- Test tokens for gas fees (available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}). See [Get Test Tokens](/smart-contracts/faucet/#get-test-tokens){target=\_blank} for a guide to using the faucet. + +## Create Your Contract + +Follow the steps below to create the ERC-721 contract: + +1. Navigate to [Remix IDE](https://remix.ethereum.org/){target=\_blank} in your web browser. +2. Select the **Create new file** button under the **contracts** folder, and name your contract `MyNFT.sol`. + + ![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-01.webp) + +3. Now, paste the following ERC-721 contract code into `MyNFT.sol`: + + ```solidity title="contracts/MyNFT.sol" + --8<-- 'code/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/MyNFT.sol' + ``` + + !!! tip + The [OpenZeppelin Contracts Wizard](https://wizard.openzeppelin.com/){target=\_blank} was used to generate this example ERC-721 contract. + +## Compile the Contract + +Solidity source code compiles into bytecode that can be deployed on the blockchain. During this process, the compiler checks the contract for syntax errors, ensures type safety, and generates the machine-readable instructions needed for blockchain execution. + +Ensure your `MyNFT.sol` contract is open in the Remix IDE Editor, and use the following steps to compile: + +1. Select the **Solidity Compiler** plugin from the left panel. +2. Select the **Compile MyToken.sol** button. + +The **Solidity Compiler** icon will display a green checkmark once the contract compiles successfully. If any issues arise during contract compilation, errors and warnings will appear in the terminal panel at the bottom of the screen. + +![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-02.webp) + +## Deploy the Contract + +Follow these steps to deploy the contract using Remix: + +1. Select **Deploy & Run Transactions** from the left panel. +2. Ensure your MetaMask wallet is connected to Polkadot Hub TestNet, then select the **Environment** dropdown and select **Injected Provider - MetaMask**. + + ![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-03.webp) + +3. Configure the contract parameters by entering the address that will own the deployed NFT contract. +4. Select the **Deploy** button to initiate the deployment. +5. Approve the transaction in your MetaMask wallet when prompted. +6. You will see the transaction details in the terminal when the deployment succeeds, including the contract address and deployment transaction hash. + +![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/nft-remix/remix-04.webp) + +Once successfully deployed, your contract will appear in the **Deployed Contracts** section, ready for interaction. + +Congratulations! You've successfully deployed an ERC-721 NFT contract to Polkadot Hub TestNet using Remix IDE. Consider the following resources to build upon your progress. + +## Where to Go Next + +
+ +- Guide __Deploy an ERC-20__ + + --- + + Walk through deploying a fully-functional ERC-20 to Polkadot Hub using Remix. + + [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/remix/) + +
diff --git a/smart-contracts/cookbook/smart-contracts/deploy-nft/remix.md b/smart-contracts/cookbook/smart-contracts/deploy-nft/remix.md deleted file mode 100644 index 3da07008e..000000000 --- a/smart-contracts/cookbook/smart-contracts/deploy-nft/remix.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: Deploy an NFT to Polkadot Hub with Remix -description: Learn how to deploy an ERC-721 NFT contract to Polkadot Hub using Remix, a browser-based IDE for quick prototyping and learning. -tutorial_badge: Beginner -categories: Basics, Smart Contracts -tools: Remix, EVM Wallet, OpenZeppelin ---- - -# Deploy an NFT with Remix - -## Introduction - -Non-Fungible Tokens (NFTs) represent unique digital assets commonly used for digital art, collectibles, gaming, and identity verification. - -This guide demonstrates how to deploy an [ERC-721](https://eips.ethereum.org/EIPS/eip-721){target=\_blank} NFT contract to [Polkadot Hub](/smart-contracts/overview/#smart-contract-development){target=\_blank}. You'll use [OpenZeppelin's battle-tested NFT implementation](https://github.com/OpenZeppelin/openzeppelin-contracts){target=\_blank} and [Remix](https://remix.ethereum.org/){target=\_blank}, a visual, browser-based environment perfect for rapid prototyping and learning. It requires no local installation and provides an intuitive interface for contract development. - -## Prerequisites - -- Basic understanding of Solidity programming and NFT standards. -- Test tokens for gas fees (available from the [Polkadot faucet](https://faucet.polkadot.io/){target=\_blank}). See the [step-by-step instructions](/smart-contracts/faucet/#get-test-tokens){target=\_blank} -- A wallet with a private key for signing transactions. - -## Access Remix - -Navigate to [Remix](https://remix.ethereum.org/){target=\_blank} in your web browser. - -The interface will load with a default workspace containing sample contracts. In this interface, you can access a file explorer, edit your code, interact with various plugins for development, and use a terminal. - -## Create Your Contract - -1. Create a new file `contracts/MyNFT.sol`. -2. Paste the following code: - - ```solidity title="contracts/MyNFT.sol" - // SPDX-License-Identifier: MIT - pragma solidity ^0.8.20; - - import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; - import "@openzeppelin/contracts/access/Ownable.sol"; - - contract MyNFT is ERC721, Ownable { - uint256 private _nextTokenId; - - constructor(address initialOwner) - ERC721("MyToken", "MTK") - Ownable(initialOwner) - {} - - function safeMint(address to) public onlyOwner { - uint256 tokenId = _nextTokenId++; - _safeMint(to, tokenId); - } - } - ``` - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-01.webp) - -## Compile - -1. Navigate to the **Solidity Compiler** tab (third icon in the left sidebar). -2. Click **Compile MyNFT.sol** or press `Ctrl+S`. - -![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-02.webp) - -Compilation errors and warnings appear in the terminal panel at the bottom of the screen. - -## Deploy - -1. Navigate to the **Deploy & Run Transactions** tab. -2. Click the **Environment** dropdown, select **Browser Extension**, and click on **Injected Provider - MetaMask**. - - ![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-03.webp) - -3. In the deploy section, enter the initial owner address in the constructor parameter field. -4. Click **Deploy**. - - ![](/images/smart-contracts/cookbook/smart-contracts/deploy-nft/remix/remix-04.webp) - -5. Approve the transaction in your MetaMask wallet. - -Your deployed contract will appear in the **Deployed Contracts** section, ready for interaction. - -## Where to Go Next - -
- -- Guide __Verify Your Contract__ - - --- - - Now that you've deployed an NFT contract, learn how to verify it with Remix. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/dev-environments/remix/verify-a-contract/) - -- Guide __Deploy an ERC-20__ - - --- - - Walk through deploying a fully-functional ERC-20 to the Polkadot Hub using Remix. - - [:octicons-arrow-right-24: Get Started](/smart-contracts/cookbook/smart-contracts/deploy-erc20/remix/) - -