This repository contains the implementation of a bridging of NFT collection on the Ethereum sepolia to amoy, map the collection to Polygon, and transfer assets over via the Polygon Bridge. To put a twist on the project, we have used an image generation tool - like DALLE 2 or Midjourney - to create the images for your NFTs.
This project involves creating and deploying an NFT collection on the Ethereum Sepolia testnet, mapping it to the Polygon Amoy testnet, and transferring the assets using the Polygon Bridge. The NFTs will be generated using DALLE 2 or Midjourney, stored on IPFS, and then minted and transferred using smart contracts and Hardhat scripts.
- MetaMask installed in your browser
- fxPortal Starter for compiling and deploying the contract
- Pinata Cloud To generate IPFS of generated image.
- Image generation tool DALL-E or Midjourney or Leonardo AI or Lexica Art.
- VS Code Integrated development Environment
- To build and run this project, we can use VS Code or GitPod.
- Create a new file by clicking on the "+" icon in the left-hand sidebar.
- Clone this repository.
- Write and Deploy an ERC721 or ERC1155.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract FuturisticCarNFT is ERC721A, Ownable {
uint256 public totalMinted;
mapping(uint256 => string) private _nftMetadata;
mapping(uint256 => string) private _nftPrompts;
// Constructor initializing the NFT collection with a name and symbol
constructor() ERC721A("FuturisticCar", "FCAR") Ownable(msg.sender) {
totalMinted = 0;
}
// Function to batch mint NFTs with corresponding metadata and prompts
function mintNFT(string[] memory metadataURIs, string[] memory descriptions) external onlyOwner {
require(metadataURIs.length == descriptions.length, "Arrays must have the same length");
uint256 startId = totalMinted;
uint256 numOfNFTs = metadataURIs.length;
// Mint the specified number of NFTs to the contract owner
_safeMint(owner(), numOfNFTs);
// Assign metadata and prompts to each newly minted NFT
for (uint256 i = 0; i < numOfNFTs; i++) {
_nftMetadata[startId + i] = metadataURIs[i];
_nftPrompts[startId + i] = descriptions[i];
}
totalMinted += numOfNFTs;
}
// Function to return the prompt description of a given token ID
function promptDescription(uint256 tokenId) external view returns (string memory) {
require(_exists(tokenId), "Prompt query for nonexistent token");
return _nftPrompts[tokenId];
}
// Override function to return the metadata URI of a given token ID
function tokenURI(uint256 tokenId) public view override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
return _nftMetadata[tokenId];
}
}
;
- Fork this repository and the clone it to there local system.
- You are required to install Node.js prior before executing the program.
- Install all dependancies by using:
npm install or npm i
- Setup your .env file with RPC URL's and your wallet Private Key.
- Compile the contract:
npx hardhat compile
- Now deploy the contract on sepolia network using the following command:
npx hardhat run scripts/deploy.js --network sepolia
- Now mint all the NFT's on sepolia network using the following command:
npx hardhat run scripts/mintNFT.js --network sepolia
- Again we now need to deposit the NFT's for the Bridge from Sepolia to Amoy using this command:
npx hardhat run scripts/approveDeposit.js --network sepolia
-
Wait for 20-30 mins to check actual bridged process, after that copy the contract address on the amoy network after it recieves all the NFTs.
-
After getting bridged address deploy getBalance.js to amoy network to get the total no. of nft it recieved from that contract:
npx hardhat run scripts/getBalance.js --network amoy
- Open MetaMask and click on the network dropdown at the top.
- Select "Add Network" and fill in the following details:
- Network Name: Sepolia test network
- New RPC URL: (https://sepolia.infura.io/v3/)
- ChainID: 11155111
- Symbol: SepoliaETH
- Save and switch to the new network.
- Open MetaMask and click on the network dropdown at the top.
- Select "Add Network" and fill in the following details:
- Network Name: Polygon Amoy Testnet
- New RPC URL: (https://rpc-amoy.polygon.technology/)
- ChainID: 80002
- Symbol: MATIC
- Save and switch to the new network.
- Go to Sepolia EtherScan(https://sepolia.etherscan.io/).
- Search for your contract address.
- Complete the verification.
- Go to PolygonScan(https://amoy.polygonscan.com/).
- Search for your contract address.
- Complete the verification.
- Note: you need some faucet balance on your network for that Links are given below.
- Sepolia Faucet: https://cloud.google.com/application/web3/faucet/ethereum/sepolia
- Amoy Faucet: https://faucet.polygon.technology/ (Joining Polygon Discord is required)
npx hardhat help
Nikhil Maurya
This project is licensed under the MIT License - see the LICENSE.md file for details