Using Hardhat

1. Initialize a Hardhat TypeScript project

Open your terminal and create a new directory for your project, then navigate into it:

Copy

mkdir my-hardhat-project && cd my-hardhat-project

Initialize an npm project:

Copy

npm init -y

Install the necessary packages for Hardhat and TypeScript:

Copy

npm install --save-dev hardhat ts-node typescript @nomiclabs/hardhat-ethers ethers

Start a new Hardhat project with TypeScript:

Copy

npx hardhat init

When prompted, make the following selections:

  • Choose "Create a TypeScript project".

  • For the .gitignore prompt, select "Yes" (or y).

  • For installing the projects dependencies select "Yes" (or y).

Copy

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

3. Configuring Harhdat for Milo

Edit the hardhat.config.ts file to include Milo Testnet settings:

Copy

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

5. Deployment

In the scripts directory, create a new file named deploy.ts:

Copy

If you get any gas related issues you will need to check what's the best gasPrice and gasLimit.

Deploy the smart contract to the Milo Testnet:

Copy

Last updated