-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8610ac6
commit 1b464bc
Showing
10 changed files
with
14,320 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
|
||
#Hardhat files | ||
cache | ||
artifacts | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# hardhat_polygon_nft | ||
# Hardhat-Polygon-Nft example | ||
An Nft example using hardhat and Polygon blockchain | ||
|
||
|
||
**Commands to create a new project using Hardhat** | ||
|
||
`mkdir hardhat-example3-nfts` | ||
`cd hardhat-example3-nfts` | ||
`npm init --yes` | ||
`npm install --save-dev hardhat` | ||
`npx hardhat` | ||
|
||
**NOTE:** create a `.env` file and add the private-key and rpc api-key in this file. Please add `.env` file to `.gitignore` as well. | ||
|
||
we will use above keys in hardhat.config.js file. | ||
|
||
`npm i dotenv` | ||
|
||
If using openzeppelin then `npm install @openzeppelin/contracts` command to add the packages. | ||
|
||
**Compile Project** | ||
|
||
`npx hardhat compile` | ||
|
||
**Test Project** | ||
|
||
`npx hardhat test` | ||
|
||
**Deploy Project** | ||
|
||
`npx hardhat run scripts/deploy.js --network <network_name from hardhat.config.js file>` | ||
for eg: `npx hardhat run scripts/deploy.js --network polygon_test` | ||
|
||
**Reference:** Hardhat [docs]("https://hardhat.org/tutorial/setting-up-the-environment.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.4; | ||
|
||
//import "hardhat/console.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
/** | ||
@title Creating Nfts | ||
@dev Contract for creating nfts using ERC721. Unlike ERC20, ERC721 lacks a decimals field, | ||
since each token is distinct and cannot be partitioned | ||
*/ | ||
contract Nfts is ERC721URIStorage, Ownable { | ||
|
||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
using Strings for uint256; | ||
|
||
mapping (uint256 => string) private _tokenURIs; | ||
|
||
constructor() ERC721("SuperNFT", "SNFT") {} | ||
|
||
/** | ||
@dev miniting NFT | ||
*/ | ||
function mint(address recepient, string memory _tokenURI) public returns (uint) { | ||
|
||
_tokenIds.increment(); | ||
uint256 newItemId = _tokenIds.current(); | ||
_mint(recepient, newItemId); | ||
_setTokenURI(newItemId, _tokenURI); | ||
|
||
return newItemId; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require("@nomiclabs/hardhat-waffle"); | ||
// for using .env file which contains private info. | ||
require('dotenv').config(); | ||
const POLYGON_TEST_PRIVATE_KEY = process.env.POLYGON_TEST_PRIVATE_KEY; | ||
const POLYGON_TEST_API_KEY = process.env.POLYGON_TEST_API_KEY; | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
module.exports = { | ||
// You can customize which network is used by default when running Hardhat by setting | ||
// the config's defaultNetwork field. If you omit this config, its default value is "hardhat" | ||
defaultNetwork: "polygon_test", | ||
networks: { | ||
hardhat: { | ||
}, | ||
// rinkeby: { | ||
// url: "https://eth-mainnet.alchemyapi.io/v2/123abc123abc123abc123abc123abcde", | ||
// accounts: [privateKey1, privateKey2, ...] | ||
// } | ||
polygon_test: { | ||
url: `https://rpc-mumbai.maticvigil.com/v1/${POLYGON_TEST_API_KEY}`, | ||
chainId: 80001, | ||
// The address to use as default sender. If not present the first account of the node is used | ||
//from: , | ||
// Its value should be "auto" or a number. If a number is used, it will be the gas limit used by default in every transaction. | ||
// If "auto" is used, the gas limit will be automatically estimated. Default value: "auto" | ||
gas: "auto", | ||
// Its value should be "auto" or a number. This parameter behaves like gas. Default value: "auto" | ||
gasPrice: "auto", | ||
// A number used to multiply the results of gas estimation to give it some slack due to the uncertainty | ||
// of the estimation process. Default value: 1 | ||
//gasMultiplier: 1, | ||
// This field controls which accounts Hardhat uses. It can use the node's accounts (by setting it to "remote"), a list | ||
// of local accounts (by setting it to an array of hex-encoded private keys), or use an HD Wallet. Default value: "remote" | ||
accounts: [`0x${POLYGON_TEST_PRIVATE_KEY}`], | ||
// You can use this field to set extra HTTP Headers to be used when making JSON-RPC requests. It accepts a JavaScript | ||
// object which maps header names to their values. Default value: undefined | ||
//httpHeaders: '', | ||
timeout: 20000 | ||
} | ||
}, | ||
solidity: { | ||
version: "0.8.4", | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 200 | ||
} | ||
} | ||
}, | ||
paths: { | ||
sources: "./contracts", | ||
tests: "./test", | ||
cache: "./cache", | ||
artifacts: "./artifacts" | ||
}, | ||
mocha: { | ||
timeout: 20000 | ||
} | ||
}; |
Oops, something went wrong.