Using Hardhat

How to deploy a sample smart contract with Hardhat on Mode

This tutorial will guide you through the process of deploying a smart contract on Mode's Ethereum L2 using Hardhat and TypeScript.

Prerequisites

  • Node.js and npm: Ensure both are installed. Download here.

  • Ethereum Wallet: A private key for the Mode Testnet that has testnet ETH. You can follow Bridging to Testnet to get some or go to Testnet Faucets. We recommend using a new wallet without real funds in case the PK gets compromised.

  • Solidity and CLI knowledge: A little knowledge is always helpful to follow along but it's not mandatory!

What you'll accomplish

  • Initialize a TypeScript-based Hardhat project.

  • Craft a basic Ethereum smart contract.

  • Set up Hardhat for Mode Testnet deployment.

  • Deploy your smart contract on Mode.

1. Initialize a Hardhat TypeScript project

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

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

Initialize an npm project:

npm init -y

Install the necessary packages for Hardhat and TypeScript:

Start a new Hardhat project with TypeScript:

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).

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:

3. Configuring Harhdat for Mode

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

Replace YOUR_PRIVATE_KEY_HERE with your Mode Testnet private key.

4. Compilation

Compile the smart contract:

5. Deployment

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

Deploy the smart contract to the Mode Testnet:

6. Check your contract in a block explorer

Verify your smart contract's deployment on the Mode Testnet block explorer: https://sepolia.explorer.mode.network/. Input the contract address from the console to view its details.

7. Conclusion

Congratulations! You've successfully deployed a smart contract on the Mode Testnet using Hardhat and TypeScript. To learn more about Mode and how to turn your code into a business, join our Discord and say hello πŸ‘‹

If you want the next challenge, you can try registering a contract for the SFS following this guide: SFS - Registering a contract with Remix \

Last updated

Was this helpful?