commit 876fa13c60bb104f1fe05fa338be2e3a00c2fb40 Author: chwan1 Date: Wed Feb 9 14:00:38 2022 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36077f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules +.env +coverage +coverage.json +typechain + +#Hardhat files +cache +artifacts diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb97640 --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/contracts/Greeter.sol b/contracts/Greeter.sol new file mode 100644 index 0000000..efffb8f --- /dev/null +++ b/contracts/Greeter.sol @@ -0,0 +1,22 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract Greeter { + string private greeting; + + constructor(string memory _greeting) { + console.log("Deploying a Greeter with greeting:", _greeting); + greeting = _greeting; + } + + function greet() public view returns (string memory) { + return greeting; + } + + function setGreeting(string memory _greeting) public { + console.log("Changing greeting from '%s' to '%s'", greeting, _greeting); + greeting = _greeting; + } +} diff --git a/contracts/UltraCoin.sol b/contracts/UltraCoin.sol new file mode 100644 index 0000000..024eb78 --- /dev/null +++ b/contracts/UltraCoin.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.2; + +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; + +contract UltraCoin is ERC20, Ownable, ERC20Permit, ERC20Votes { + constructor() ERC20("Ultra Coin", "UC") ERC20Permit("Ultra Coin") { + _mint(msg.sender, 53121881 * 10 ** decimals()); + } + + function mint(address to, uint256 amount) public onlyOwner { + _mint(to, amount); + } + + // The following functions are overrides required by Solidity. + + function _afterTokenTransfer(address from, address to, uint256 amount) + internal + override(ERC20, ERC20Votes) + { + super._afterTokenTransfer(from, to, amount); + } + + function _mint(address to, uint256 amount) + internal + override(ERC20, ERC20Votes) + { + super._mint(to, amount); + } + + function _burn(address account, uint256 amount) + internal + override(ERC20, ERC20Votes) + { + super._burn(account, amount); + } +} diff --git a/hardhat.config.js b/hardhat.config.js new file mode 100644 index 0000000..cfeed55 --- /dev/null +++ b/hardhat.config.js @@ -0,0 +1,21 @@ +require("@nomiclabs/hardhat-waffle"); + +// 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 = { + solidity: "0.8.4", +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..5d02bba --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "hardhat-project", + "devDependencies": { + "@nomiclabs/hardhat-ethers": "^2.0.0", + "@nomiclabs/hardhat-waffle": "^2.0.0", + "@openzeppelin/hardhat-upgrades": "^1.14.0", + "chai": "^4.2.0", + "ethereum-waffle": "^3.0.0", + "ethers": "^5.0.0", + "hardhat": "^2.8.3" + }, + "dependencies": { + "@openzeppelin/contracts": "^4.4.2" + } +} diff --git a/scripts/sample-script.js b/scripts/sample-script.js new file mode 100644 index 0000000..90cd819 --- /dev/null +++ b/scripts/sample-script.js @@ -0,0 +1,32 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node