Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ runs:
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24

- name: Install
run: npm install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coverage
coverage.json
typechain
typechain-types
types

# Hardhat files
cache
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
.env
.idea
typechain-types
types
coverage
5 changes: 4 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"func-visibility": ["error", { "ignoreConstructors": true }]
"func-visibility": ["error", { "ignoreConstructors": true }],
"use-natspec": "off",
"gas-calldata-parameters": "off",
"gas-increment-by-one": "off"
}
}
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,13 @@ https://hardhat.org/getting-started/

Feel free to add more networks in `hardhat.config.ts` file.

## Hardhat Shorthand
## Common Hardhat Commands

We recommend installing `hh autocomplete` so you can use `hh` shorthand globally.

```shell
npm i -g hardhat-shorthand
```

https://hardhat.org/guides/shorthand.html

### Common Shorthand Commands

- `hh compile` - to compile smart contract and generate typechain ts bindings
- `hh test` - to run tests
- `hh igntion` - to deploy smart contracts
- `hh node` - to run a localhost node
- `hh help` - to see all available commands
- `hh TABTAB` - to use autocomplete
- `npx hardhat compile` - to compile smart contract and generate typechain ts bindings
- `npx hardhat test` - to run tests
- `npx hardhat ignition` - to deploy smart contracts
- `npx hardhat node` - to run a localhost node
- `npx hardhat help` - to see all available commands

## Usage

Expand All @@ -105,11 +94,32 @@ npm run compile

#### 3. Environment Setup

Create `.env` file and add your environment variables. You can use `.env.example` as a template.
This project uses [Hardhat Keystore](https://hardhat.org/plugins/nomicfoundation-hardhat-keystore) to securely manage sensitive configuration variables like private keys and RPC URLs. Secrets are stored encrypted and never committed to disk in plain text.

**Set your private key**

```shell
npx hardhat keystore set PRIVATE_KEY
```

**Set your RPC URLs** (for the networks you plan to use)

```shell
npx hardhat keystore set SEPOLIA_RPC_URL
npx hardhat keystore set MAINNET_RPC_URL
```

**Set your Etherscan API key** (for contract verification)

If you are going to use public network, make sure you include the right RPC provider for that network.
```shell
npx hardhat keystore set ETHERSCAN_API_KEY
```

**List stored variables**

Make sure you include either `MNEMONIC` or `PRIVATE_KEY` in your `.env` file.
```shell
npx hardhat keystore list
```

### Example Flow - Deploy ERC721 Token

Expand All @@ -118,34 +128,34 @@ Make sure you include either `MNEMONIC` or `PRIVATE_KEY` in your `.env` file.
#### 1.1 Deploy BasicERC721 Contract

```shell
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia
```

**Verify contract**

```shell
hh ignition verify chain-11155111
npx hardhat ignition verify chain-11155111 --network sepolia
```

#### 1.2 Deploy and Verify

```shell
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify
```

#### 1.3 Deploy and Verify with Custom Parameters

Look at `ignition/parameters/custom.json` to see how to adjust contract parameters

```shell
hh ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify --parameters ignition/parameters/custom.json
npx hardhat ignition deploy ignition/modules/BasicERC721Module.ts --network sepolia --verify --parameters ignition/parameters/custom.json
```

#### 2. Interact With Contract - Mint

```shell
hh erc721-mint \
--contract 0x1FEB5675Be6F256c4680BE447D6C353E02e04fb9 \
npx hardhat erc721-mint \
--contract 0x3fCB912bfb67B78121C5F326C24fBb0D2ca146dD \
--recipient 0x73faDd7E476a9Bc2dA6D1512A528366A3E50c3cF \
--network sepolia
```
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig([
"**/artifacts",
"**/cache",
"**/typechain-types",
"**/types",
]),
{
extends: compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"),
Expand Down
101 changes: 47 additions & 54 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,59 @@
import "@nomicfoundation/hardhat-toolbox"
import { defineConfig, configVariable } from "hardhat/config"
import hardhatToolboxMochaEthers from "@nomicfoundation/hardhat-toolbox-mocha-ethers"
import hardhatVerify from "@nomicfoundation/hardhat-verify"

import { HardhatUserConfig } from "hardhat/config"
import { erc20MintTask } from "./tasks/erc20/mint.js"
import { erc721MintTask } from "./tasks/erc721/mint.js"
import { erc721BaseUriTask } from "./tasks/erc721/base-uri.js"
import { erc721ContractUriTask } from "./tasks/erc721/contract-uri.js"
import { erc1155MintTask } from "./tasks/erc1155/mint.js"
import { erc1155BaseUriTask } from "./tasks/erc1155/base-uri.js"
import { erc1155ContractUriTask } from "./tasks/erc1155/contract-uri.js"
import { accountsTask } from "./tasks/utils/accounts.js"
import { balanceTask } from "./tasks/utils/balance.js"
import { blockNumberTask } from "./tasks/utils/block-number.js"
import { sendEthTask } from "./tasks/utils/send-eth.js"

import "@nomiclabs/hardhat-solhint"
import "solidity-coverage"

import "dotenv/config"

import "./tasks"

const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || "https://eth-mainnet.g.alchemy.com/v2/your-api-key"
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
const MATIC_RPC_URL = process.env.MATIC_RPC_URL || "https://polygon-mainnet.g.alchemy.com/v2/your-api-key"
const MUMBAI_RPC_URL = process.env.MUMBAI_RPC_URL || "https://polygon-mumbai.g.alchemy.com/v2/v3/your-api-key"

const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "api-key"
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY || "api-key"

// Import MNEMONIC or single private key
const MNEMONIC = process.env.MNEMONIC || "your mnemonic"
const PRIVATE_KEY = process.env.PRIVATE_KEY

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
export default defineConfig({
plugins: [hardhatToolboxMochaEthers, hardhatVerify],
tasks: [
erc20MintTask,
erc721MintTask,
erc721BaseUriTask,
erc721ContractUriTask,
erc1155MintTask,
erc1155BaseUriTask,
erc1155ContractUriTask,
accountsTask,
balanceTask,
blockNumberTask,
sendEthTask,
],
networks: {
mainnet: {
url: MAINNET_RPC_URL,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
},
hardhat: {
// // If you want to do some forking, uncomment this
// forking: {
// url: MAINNET_RPC_URL
// }
},
localhost: {
url: "http://127.0.0.1:8545",
type: "http",
url: configVariable("MAINNET_RPC_URL"),
accounts: [configVariable("PRIVATE_KEY")],
},
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
type: "http",
url: configVariable("SEPOLIA_RPC_URL"),
accounts: [configVariable("PRIVATE_KEY")],
},
matic: {
url: MATIC_RPC_URL,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
polygon: {
type: "http",
url: configVariable("POLYGON_RPC_URL"),
accounts: [configVariable("PRIVATE_KEY")],
},
mumbai: {
url: MUMBAI_RPC_URL,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : { mnemonic: MNEMONIC },
amoy: {
type: "http",
url: configVariable("AMOY_RPC_URL"),
accounts: [configVariable("PRIVATE_KEY")],
},
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: {
mainnet: ETHERSCAN_API_KEY,
sepolia: ETHERSCAN_API_KEY,
// Polygon
polygon: POLYGONSCAN_API_KEY,
polygonMumbai: POLYGONSCAN_API_KEY,
verify: {
etherscan: {
apiKey: configVariable("ETHERSCAN_API_KEY"),
},
},
solidity: {
Expand All @@ -68,6 +63,4 @@ const config: HardhatUserConfig = {
},
],
},
}

export default config
})
Loading