-
Notifications
You must be signed in to change notification settings - Fork 0
HardHat guide
This guide provides a concise introduction to Hardhat's structure and basic functionality. For more comprehensive documentation and tutorials, please refer to the official Hardhat resources:
When you create a new repository using the core-hardhat-template, the following folder structure is provided:
.
├── contracts
│ └── MyToken.sol
├── hardhat.config.ts
└── scripts
├── contracts.ts
└── tasks
Here's what each folder or file is for:
contracts: Contains Solidity contracts. Your project logic is written here.
hardhat.config.ts: The main configuration file for Hardhat, specifying available networks and other required settings.
scripts: User scripts, the subfolder task contains some custom logic added to hardhat, the main folder contains the deployment script.
This guide demonstrates how to deploy the provided MyToken.sol contract.
Ensure all dependencies are installed by running:
npm install
⚠️ Warning: The default mnemonic is publicly known. Do not use it on public networks. Any funds transferred using this mnemonic will be at risk of being stolen. Use it only for local testing and development purposes.
Before deploying to public networks, ensure your wallet is configured and has sufficient CFX for deployment.
Add a new wallet with:
devkit wallet addThis launches an interactive interface for generating or entering a mnemonic passphrase. After creating a wallet, activate it with:
devkit wallet selectThe wallet configuration is persistent, so this step is only required when adding or changing wallets.
For more wallet commands, run:
devkit wallet -hOr refer to the Devkit CLI Wiki.
The Conflux blockchain has two partitions:
Core Space: The native partition, used in this guide. ESpace: An EVM-compatible partition.
To start the Conflux node, use:
hh nodeAfter a few seconds, you should see output similar to this:
√ Node started successfully!
⠦ 12/18/2024, 9:21:52 PM | Core Block: 33 | Espace Block: 29 | Default Keystore | [f]: Faucet [q]: Quit
The block count will increment as the node processes blocks. You can leave this terminal open and use a new terminal to continue.
To deploy the contract first you need to compile the contract running:
hh compileIt will generate an output similar to this:
Downloading compiler 0.8.28
Compiled 1 Solidity file successfully (evm target: paris).
After the contract is compiled you can execute the deployment script:
hh run scripts/contracts.ts --network confluxCoreLocal
Note: if the parameter --network is not specified the script will fail
Example output:
MyToken address: NET2029:TYPE.CONTRACT:ACBVM2FA0U69UYFTAF6H4R5GM7HT5DXAJJGF1APXTJ
Initial supply of MyToken: 1000000
New supply of MyToken: 1500000
The contract address (e.g., NET2029:TYPE.CONTRACT:ACBVM2FA0U69UYFTAF6H4R5GM7HT5DXAJJGF1APXTJ) can be used in your frontend or client applications.
To deploy to other networks like testnet (confluxCoreTestnet) or mainnet (confluxCore), follow the same steps, ensuring you have sufficient funds:
hh balance --network confluxCoreTestnetWith these steps, you’re now ready to deploy smart contracts on Conflux Core!