Skip to content

Commit

Permalink
setup hardhat folder
Browse files Browse the repository at this point in the history
  • Loading branch information
imysh578 committed Mar 21, 2022
1 parent e989401 commit 43541b9
Show file tree
Hide file tree
Showing 19 changed files with 41,958 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _hardhat/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
artifacts
cache
coverage
24 changes: 24 additions & 0 deletions _hardhat/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
plugins: ["@typescript-eslint"],
extends: [
"standard",
"plugin:prettier/recommended",
"plugin:node/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
},
rules: {
"node/no-unsupported-features/es-syntax": [
"error",
{ ignores: ["modules"] },
],
},
};
9 changes: 9 additions & 0 deletions _hardhat/.gitignore
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
3 changes: 3 additions & 0 deletions _hardhat/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hardhat.config.ts
scripts
test
5 changes: 5 additions & 0 deletions _hardhat/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
artifacts
cache
coverage*
gasReporterOutput.json
1 change: 1 addition & 0 deletions _hardhat/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 7 additions & 0 deletions _hardhat/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
1 change: 1 addition & 0 deletions _hardhat/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
46 changes: 46 additions & 0 deletions _hardhat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Advanced Sample Hardhat Project

This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.

The project 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. It also comes with a variety of other tools, preconfigured to work with the project code.

Try running some of the following tasks:

```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
npx hardhat run scripts/deploy.ts
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix
```

# Etherscan verification

To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.

In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:

```shell
hardhat run --network ropsten scripts/deploy.ts
```

Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:

```shell
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
```

# Performance optimizations

For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations).
22 changes: 22 additions & 0 deletions _hardhat/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 8 additions & 0 deletions _hardhat/contracts/Musit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "./Ownable.sol";

contract Musit is Ownable {

}
45 changes: 45 additions & 0 deletions _hardhat/contracts/Ownable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

contract Ownable {
address internal _owner; // owner : 배포자

event OwnershipTransferred(address oldOwner,address newOwner);

constructor () {
_transferOwnership(msg.sender);
}

modifier onlyOwner {
require(msg.sender == _owner, "Ownable: This is for only owner!");
_;
}

// 컨트랙트 주소에 담긴 이더를 소유자에게 출금
function withdraw () onlyOwner external {
payable(_owner).transfer(address(this).balance);
}

// 소유권 출력 함수
function owner() public view returns(address) {
return _owner;
}

// 소유권 포기 함수
function _renounceOwnership() public onlyOwner {
_transferOwnership(address(this));
}

// 소유자 이전 함수 (소유자가 address(0)가 아닌 경우)
function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(_newOwner);
}

// 소유자 이전 함수
function _transferOwnership(address _newOwner) internal {
address oldOwner = _owner;
_owner = _newOwner;
emit OwnershipTransferred(oldOwner, _newOwner);
}
}
15 changes: 15 additions & 0 deletions _hardhat/contracts/SongNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

// TODO: ERC721, Ownable 컨트랙트 불러오기

contract SongNFT { // 불러온 컨트랙트들 상속하기
/**
TODO:
1. variables : 민팅가격, 발행 총 수량, 현재까지 발행된 민팅 수량, 민팅 가능 여부 State, 토큰 uri, 자금 회수용 지갑(?), 주소 당 최대 민팅 수량, 트랜잭션 당 최대 민팅 수량
2. mapping : 주소 당 민팅 총 수량
3. constructor : payable, ERC721을 통해서 토큰 이름 및 심볼 적기
4. function : 민팅 가능 여부 설정 함수, 토큰 uri 설정 함수, 토큰 uri 출력 함수, 출금 함수, 민팅 함수
*/

}
43 changes: 43 additions & 0 deletions _hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as dotenv from "dotenv";

import { HardhatUserConfig, task } from "hardhat/config";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "hardhat-gas-reporter";
import "solidity-coverage";

dotenv.config();

// 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

const config: HardhatUserConfig = {
solidity: "0.8.4",
networks: {
ropsten: {
url: process.env.ROPSTEN_URL || "",
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: "USD",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
};

export default config;
Loading

0 comments on commit 43541b9

Please sign in to comment.