Build an NFT Collection using Flutter | by Bo Hellgren | Feb, 2022

3. Get a pockets

To retailer cryptocurrency and NFTs, and pay for Blockchain transactions, you want a wallet. On this mission, we are going to use MetaMask. You may set up it as a Chrome extension in your pc, as an app in your Android cell, or each (there’s a sync function). We’ll use the Chrome extension. Go to the MetaMask house web page and click on Set up MetaMask for Chrome.

Concerning which blockchain to make use of to your NFTs, there are a number of potentialities. Ethereum is the place essentially the most well-known collections reside, however it is rather costly to make use of as a result of heavy transaction charges. For this mission, we are going to use Polygon which additionally may be very standard for NFTs. Each chains have side-chains totally free testing. Ethereum has side-chains Rinkeby and Ropsten, Polygon has Mumbai. To look at transactions, contracts, wallets, and so forth on Polygon use the Polygon Chain Explorer at That is free and doesn’t require a consumer id or logon. To do the identical on Mumbai, go to Bookmark these, as a result of you’ll use them loads.

So as to add help for Polygon and Mumbai in your pockets, you possibly can click on the Networks pulldown in your pockets after which click on Add community. However there may be a neater manner: Go to, scroll right down to the underside of the net web page, and click on the Add Polygon Community button. Then do the identical for Mumbai: Go to, scroll right down to the underside of the net web page, and click on the Add Mumbai Community button.

You additionally want some cryptocurrency to pay to your transactions on Mumbai. The forex used for that is known as MATIC. Change your pockets to Mumbai. Copy your pockets handle. Go to the Polygon Faucet. Paste your pockets handle within the Get Check Tokens panel, choose Matic Token, and click on Submit. After a while, you’ll have 0.5 MATIC in your pockets, which you’ll be able to see on when you enter your contract handle — examine Steadiness and Inside Txns. However perhaps you don’t see it in MetaMask. You will need to then add help for MATIC in MetaMask by clicking Import Tokens below Belongings. Or, once more there may be a neater manner: Go to (not Mumbai), and enter Matic Token within the search subject. On the Profile abstract line, to the far proper, click on the three-vertical-dots. Click on Add Token to Web3 Pockets.

You now have a pockets that can be utilized for testing.

4. Create and deploy a Good Contract

On this step, we are going to write a Good Contract, compile it and deploy it on the Polygon check chain known as Mumbai.

The Good Contract retains monitor of your NFTs — what number of there are, and for every NFT the URL for the outline (the JSON file), who owns it (the pockets handle), and extra. It’s also used to create new NFTs — a course of known as minting an NFT.

Good Contracts are written in a particular language known as Solidity. It’s influenced by JavaScript. Thankfully, there are customary contracts you possibly can embrace after which solely add a number of strains particular to your mission.

Comply with the steps beneath. There is a wonderful article by Bhaskar Dutta on Figment Learn describing what we do on this part, if you would like extra element.

  1. Be sure you have a latest model of node.js (15 or later). With node.js come the instructions npm and npx which we are going to use loads.
  2. Create a listing for this a part of the mission, e.g. Circles, and cd to it.

3. Set up Hardhat, a growth atmosphere for blockchain apps. Run the command npm set up -g hardhat.

4. Create a Hardhat mission. Run the command npx hardhat. Press Enter on all questions, taking the defaults, together with “Create a primary pattern mission”.

5. Hardhat will let you know to put in a number of extra packages as growth dependencies. Run the instructions (ignore the warnings)

npm set up --save-dev "hardhat@2.8.3"
npm set up --save-dev "@nomiclabs/hardhat-waffle@2.0.0"
npm set up --save-dev "ethereum-waffle@3.0.0"
npm set up --save-dev "chai@4.2.0"
npm set up --save-dev "@nomiclabs/hardhat-ethers@2.0.0"
npm set up --save-dev "ethers@5.0.0"
npm set up @nomiclabs/hardhat-etherscan

6. Set up the OpenZeppelin contracts library. That is the place we get the usual contract for NFTs, known as ERC721.sol. Run the command npm set up @openzeppelin/contracts

7. Lastly set up the dotenv bundle. This enables us to place issues like pockets handle and IPFS CIDs within the .env file as a substitute of hard-coding them. Run the command npm set up dotenv.

8. Open the Circles listing in Android Studio or VS Code and familiarize your self with the contents. harhat.config.js is a configuration file for Hardhat. The contracts folder is the place the Solidity contracts go. It has a pattern contract named Greeter.sol. The scripts folder incorporates JavaScript recordsdata for deploying contracts and extra.

9. To examine that the set up is OK, compile the pattern contract: npx hardhat compile.

10. Create a file named .env within the root and add these strains:

CONTRACT_NAME = "John Doe's Circles Assortment"
WALLET_OWNER = "0x6f3298d259e6EC1c48FA0d6265E8D49ad78EBFD7"
JSON_CID = "QmQuXH6UCaY9iAYt5VcrTurF4BBeLC3XxxRfMxCuU4g3Gu"
IMAGES_CID = "QmPDLL5r7mxDZ3nhVVFzLxE5fRxxfDW1UAqeZsvRYoEzdq"

the place

  • CONTRACT_NAME is the identify you need to give to your contract. Change John Doe with your personal identify. The identify doesn’t should be distinctive, however since it’s going to even be the default assortment identify in OpenSea, it is going to be complicated if all of us use the identical identify.
  • CONTRACT_SYMBOL is the identify you need to give to the kind of token used, normally three or 4 characters. Change JD with your personal initials.
  • CONTRACT_ADDRESS can be crammed in later after the contract has been deployed
  • In WALLET_OWNER put the general public handle of your MetaMask pockets.
  • In WALLET_PRIVATE_KEY put the non-public key of your pockets. Open the pockets, go to Account particulars, and selected Export non-public key. Somebody who is aware of this key can steal all of the property in your pockets. So that you have to be very cautious to not give entry to the .env file. Be sure .env is listed within the .gitgnore file.
  • POLYGONSCAN_KEY is defined beneath.
  • ALCHEMY_KEY_TEST and _PROD are defined beneath.

11. Put the IPFS CIDs obtained above in JSON_CID and IMAGES_CID.

12. To make use of Polygonscan programmatically, we want an API. Go to and register for the Free API Plan. Create an API key and enter it within the .env file as POLYGONSCAN_KEY. (The identical secret’s used for Mumbai).

13. We will even use a blockchain developer platform known as Alchemy. Register, go to the dashboard, click on +Create APP, and get two API keys, one for testing on Mumbai and one for manufacturing on Polygon Mainnet. Put them within the .env file (beginning with https://).

14. Replace hardhat.config.js to appear like this:

15. Within the contracts folder, delete Greeter.sol and add our contract NFT.sol:

For explanations, see the Figment article. The isApproveForAll override is one thing required by OpenSea, as described here.

16. Compile the contract: npx hardhat compile. It is best to get “Compilation completed efficiently”.

17. Within the scripts folder, add a script known as deploy.js:

18. Now run the command
npx hardhat run scripts/deploy.js –network Mumbai

It is best to get a message like

John Doe’s Circles Assortment (JDCC) deployed to: 0x410FbeCc285F3a833f09d51D8CC10f8e7d30F556

That is your contract handle. Copy/paste it to the .env file! (Ctrl/m to repeat).

In the event you get Error: inadequate funds for intrinsic transaction price, double-check WALLET_OWNER and WALLET_PRIVATE_KEY, and that you’ve some MATIC forex there.

19. Study the contract in mumbai.polygonscan. You received’t see a lot since it’s not verified but. As soon as verified, a sensible contract’s supply code turns into publicly obtainable and verifiable. This creates transparency and belief. And it is possible for you to to handle the contract utilizing Polygonscan. Add a script named confirm.js to scripts:

Then run the command

npx hardhat run scripts/confirm.js –network Mumbai

It is best to get (this will likely take a while) a message like

John Doe’s Circles Assortment (JDCC) verified at: (contract handle)

In the event you get errors, strive npx hardhat clear, npx hardhat compile, and do confirm once more.

20. Now study the contract in mumbai.polygonscan once more. Click on Contract which ought to now have a inexperienced checkmark, which means that it’s verified. Click on Learn Contract and study the data you (anybody) can get concerning the contract. Click on Write Contract and Connect with Web3 and study the way you (solely you!) can replace the contract. Most significantly, you possibly can create NFTs (JDCC tokens) utilizing the mint operate. In the event you solely need to mint a number of NFTs, this is likely to be adequate. However if you would like 100 or 10,000 NFTs, you need to use a program to mint, which is what we do within the subsequent part.

More Posts