move er721-101 to solidity dir

This commit is contained in:
bt3gl 2022-03-23 17:57:49 +04:00
parent bb3dcb5b32
commit ec24a4b414
8 changed files with 0 additions and 0 deletions

BIN
solidity/erc721-solidity-101/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,5 @@
API_URL = "https://eth-rinkeby.alchemyapi.io/v2/<project>"
PUBLIC_KEY =
PRIVATE_KEY =
METADATA_URL = <pinata IPFS cid dor metadata>"
CONTRACT_ADDRESS =

View file

@ -0,0 +1,20 @@
# One: A special summer
1. Compile contract:
```
npx hardhat compile
```
2. Deploy contract:
```
npx hardhat run scripts/deploy-contract.js --network rinkeby
```
3. Mint NFT:
```
node scripts/mint-nft.js
```

View file

@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.3 <0.9.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MiaNFT is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() public ERC721("Mia's NFT, "NFT") {}
function mintNFT(address recipient, string memory tokenURI)
public onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}

View file

@ -0,0 +1,19 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
module.exports = {
solidity: "0.7.3",
defaultNetwork: "rinkeby",
networks: {
hardhat: {},
rinkeby: {
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
},
}

View file

@ -0,0 +1,23 @@
{
"name": "MiaNFT",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mia von Steinkirch",
"license": "MIT",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^3.1.0-solc-0.7",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.6",
"hardhat": "^2.6.2"
},
"dependencies": {
"@alch/alchemy-web3": "^1.1.4",
"dotenv": "^10.0.0"
}
}

View file

@ -0,0 +1,14 @@
async function main() {
const nft = await ethers.getContractFactory("MiaNFT");
const nft_deploy = await nft.deploy();
console.log(" ⛓🧱✨ Contract address:", nft_deploy.address);
console.log(" ➡️ (Please add this string to .env)");
}
main()
.then(() => process.exit(0))
.catch(e => {
console.error(e);
process.exit(1);
});

View file

@ -0,0 +1,41 @@
require('dotenv').config();
const PUBLIC_KEY = process.env.PUBLIC_KEY;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const API_URL = process.env.API_URL;
const METADATA_URL = process.env.METADATA_URL;
const CONTRACT_ADDRESS = process.env.CONTRACT_ADDRESS;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(API_URL);
const contract = require("../artifacts/contracts/MiaNFT.sol/MiaNFT.json");
const nftContract = new web3.eth.Contract(contract.abi, CONTRACT_ADDRESS);
async function mintNFT(tokenURI) {
const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, 'latest');
const transaction = {
'from': PUBLIC_KEY,
'to': CONTRACT_ADDRESS,
'nonce': nonce,
'gas': 500000,
'maxPriorityFeePerGas': 1999999987,
'data': nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI()
};
const sign = web3.eth.accounts.signTransaction(transaction, PRIVATE_KEY);
sign.then((signedTransaction) => {
web3.eth.sendSignedTransaction(signedTransaction.rawTransaction, function(e, hash) {
if (!e) {
console.log("💾 Transaction hash: ", hash);
} else {
console.log("ERROR:", e)
}
});
}).catch((e) => {
console.log("ERROR:", e);
});
}
mintNFT(METADATA_URL);