-
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
0 parents
commit 8efee97
Showing
24 changed files
with
12,008 additions
and
0 deletions.
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,9 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
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,15 @@ | ||
# Basic Sample Hardhat Project | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat accounts | ||
npx hardhat compile | ||
npx hardhat clean | ||
npx hardhat test | ||
npx hardhat node | ||
node scripts/sample-script.js | ||
npx hardhat help | ||
``` |
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,4 @@ | ||
module.exports = { | ||
CRYPTO_DEVS_NFT_CONTRACT_ADDRESS: | ||
"0x37303618c6258EBCDE2fea24c5fE3968bD25E79c", | ||
}; |
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,56 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./ICryptoDevs.sol"; | ||
|
||
contract CryptoDevToken is ERC20, Ownable { | ||
uint256 public constant tokenPrice = 0.001 ether; | ||
uint256 public constant tokensPerNFT = 10 * 10**18; | ||
uint256 public constant maxTotalSupply = 10000 * 10**18; | ||
ICryptoDevs CryptoDevsNFT; | ||
mapping(uint256 => bool) public tokenIdsClaimed; | ||
|
||
constructor(address _cryptoDevsContract) ERC20("Crypto Dev Token", "CD") { | ||
CryptoDevsNFT = ICryptoDevs(_cryptoDevsContract); | ||
} | ||
|
||
function mint(uint256 amount) public payable { | ||
uint256 _requiredAmount = amount * tokenPrice; | ||
require(msg.value >= _requiredAmount, "Ether sent is incorrect"); | ||
uint256 amountWithDecimals = amount * 10**18; | ||
require( | ||
totalSupply() + amountWithDecimals <= maxTotalSupply, | ||
"Exceeds the max total supply available." | ||
); | ||
_mint(msg.sender, amountWithDecimals); | ||
} | ||
|
||
function claim() public { | ||
address sender = msg.sender; | ||
uint256 balance = CryptoDevsNFT.balanceOf(sender); | ||
require(balance > 0, "You dont own any Crypto Dev NFT's"); | ||
uint256 amount = 0; | ||
for (uint256 i = 0; i < balance; i++) { | ||
uint256 tokenId = CryptoDevsNFT.tokenOfOwnerByIndex(sender, i); | ||
if (!tokenIdsClaimed[tokenId]) { | ||
amount += 1; | ||
tokenIdsClaimed[tokenId] = true; | ||
} | ||
} | ||
require(amount > 0, "You have already claimed all the tokens"); | ||
_mint(sender, amount * tokensPerNFT); | ||
} | ||
|
||
function withdraw() public onlyOwner { | ||
address _owner = owner(); | ||
uint256 amount = address(this).balance; | ||
(bool sent, ) = _owner.call{value: amount}(""); | ||
require(sent, "Failed to send Ether"); | ||
} | ||
|
||
receive() external payable {} | ||
|
||
fallback() external payable {} | ||
} |
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,14 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.0; | ||
|
||
interface ICryptoDevs { | ||
function tokenOfOwnerByIndex(address _address, uint256 index) | ||
external | ||
view | ||
returns (uint256 tokenId); | ||
|
||
function balanceOf(address _address) | ||
external | ||
view | ||
returns (uint256 balance); | ||
} |
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,16 @@ | ||
require("@nomiclabs/hardhat-waffle"); | ||
require("dotenv").config({ path: ".env" }); | ||
|
||
const ALCHEMY_API_KEY_URL = process.env.ALCHEMY_API_KEY_URL; | ||
|
||
const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY; | ||
|
||
module.exports = { | ||
solidity: "0.8.4", | ||
networks: { | ||
rinkeby: { | ||
url: ALCHEMY_API_KEY_URL, | ||
accounts: [RINKEBY_PRIVATE_KEY], | ||
}, | ||
}, | ||
}; |
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,24 @@ | ||
{ | ||
"name": "hardhat-tutorial", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@nomiclabs/hardhat-ethers": "^2.0.6", | ||
"@nomiclabs/hardhat-waffle": "^2.0.3", | ||
"chai": "^4.3.6", | ||
"ethereum-waffle": "^3.4.4", | ||
"ethers": "^5.6.8", | ||
"hardhat": "^2.9.9" | ||
}, | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^4.6.0", | ||
"dotenv": "^16.0.1" | ||
} | ||
} |
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,26 @@ | ||
const { ethers } = require("hardhat"); | ||
const { CRYPTO_DEVS_NFT_CONTRACT_ADDRESS } = require("../constants"); | ||
|
||
async function main() { | ||
const cryptoDevsNFTContract = CRYPTO_DEVS_NFT_CONTRACT_ADDRESS; | ||
const cryptoDevsTokenContract = await ethers.getContractFactory( | ||
"CryptoDevToken" | ||
); | ||
const deployedCryptoDevsTokenContract = await cryptoDevsTokenContract.deploy( | ||
cryptoDevsNFTContract | ||
); | ||
|
||
await deployedCryptoDevsTokenContract.deployed(); | ||
|
||
console.log( | ||
"Crypto Devs Token Contract Address:", | ||
deployedCryptoDevsTokenContract.address | ||
); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
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,19 @@ | ||
const { expect } = require("chai"); | ||
const { ethers } = require("hardhat"); | ||
|
||
describe("Greeter", function () { | ||
it("Should return the new greeting once it's changed", async function () { | ||
const Greeter = await ethers.getContractFactory("Greeter"); | ||
const greeter = await Greeter.deploy("Hello, world!"); | ||
await greeter.deployed(); | ||
|
||
expect(await greeter.greet()).to.equal("Hello, world!"); | ||
|
||
const setGreetingTx = await greeter.setGreeting("Hola, mundo!"); | ||
|
||
// wait until the transaction is mined | ||
await setGreetingTx.wait(); | ||
|
||
expect(await greeter.greet()).to.equal("Hola, mundo!"); | ||
}); | ||
}); |
Oops, something went wrong.