Using Hardhat
How to deploy a sample smart contract with Hardhat on Mode
Last updated
Was this helpful?
How to deploy a sample smart contract with Hardhat on Mode
Last updated
Was this helpful?
This tutorial will guide you through the process of deploying a smart contract on Mode's Ethereum L2 using Hardhat and TypeScript.
Node.js and npm: Ensure both are installed. .
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!
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.
Open your terminal and create a new directory for your project, then navigate into it:
Initialize an npm project:
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
).
In the contracts
directory, delete the sample smart contract Lock.sol
and then create a new file named HelloWorld.sol
:
Edit the hardhat.config.ts
file to include Mode Testnet settings:
Replace YOUR_PRIVATE_KEY_HERE
with your Mode 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
Compile the smart contract:
In the scripts
directory, create a new file named deploy.ts
:
Deploy the smart contract to the Mode Testnet:
If you want the next challenge, you can try registering a contract for the SFS following this guide: SFS - Registering a contract with Remix
If you get any gas related issues you will need to check what's the best gasPrice and gasLimit, you can find some info about the state of the chain in
Verify your smart contract's deployment on the Mode Testnet block explorer: . Input the contract address from the console to view its details.
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 and say hello ๐