For installing the projects dependencies select "Yes" (or y).
Copy
[~/Milo/my-hardhat-project]$ npx hardhat
888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 88b 888P d88 888 888 88b 88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 Y888888 888 Y88888 888 888 Y888888 Y888
๐ท Welcome to Hardhat v2.18.2 ๐ทโ
โ What do you want to do? ยท Create a TypeScript project
โ Hardhat project root: ยท /Users/Milo/my-hardhat-project
โ Do you want to add a .gitignore? (Y/n) ยท y
โ Do you want to install this sample project's dependencies with npm (@nomicfoundation/hardhat-toolbox)? (Y/n) ยท y
2. Drafting the Smart Contract
In the contracts directory, delete the sample smart contract Lock.sol and then create a new file named HelloWorld.sol:
Copy
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HelloWorld {
string public greet = "Hello, Milo!";
function setGreet(string memory _greet) public {
greet = _greet;
}
function getGreet() public view returns (string memory) {
return greet;
}
}
3. Configuring Harhdat for Milo
Edit the hardhat.config.ts file to include Milo Testnet settings:
Copy
import "@nomiclabs/hardhat-ethers";
import { HardhatUserConfig } from "hardhat/config";
const config: HardhatUserConfig = {
networks: {
Milo: {
url: "https://sepolia.Milo.network",
chainId: 919,
accounts: ["YOUR_PRIVATE_KEY_HERE"] //BE VERY CAREFUL, DO NOT PUSH THIS TO GITHUB
}
},
solidity: "0.8.0",
};
export default config;
Replace YOUR_PRIVATE_KEY_HERE with your Milo Testnet private key.
IMPORTANT: Do not push your hardhat.config.ts file to github nor share your private key with anyone. It is a very common mistake to push your PK to github so make sure that in the .gitignore you add the hardhat.config.ts
4. Compilation
Compile the smart contract:
Copy
npx hardhat compile
5. Deployment
In the scripts directory, create a new file named deploy.ts:
Copy
import { ethers } from "hardhat";
async function main() {
const HelloWorld = await ethers.getContractFactory("HelloWorld");
const gasPrice = ethers.utils.parseUnits('10', 'gwei'); // Adjust the '10' as needed
const gasLimit = 500000; // Adjust this value based on your needs
const helloWorld = await HelloWorld.deploy({ gasPrice: gasPrice, gasLimit: gasLimit });
await helloWorld.deployed();
console.log("HelloWorld deployed to:", helloWorld.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
If you get any gas related issues you will need to check what's the best gasPrice and gasLimit.