2025-02-10 18:46:43 +05:30
---
title : Using Hardhat with Status Network
description : Step-by-step tutorial for deploying smart contracts on Status Network using Hardhat and TypeScript. Learn about project setup, configuration, and contract deployment.
keywords : [ Hardhat tutorial, smart contract deployment, Status Network development, TypeScript, blockchain development, web3 development]
---
2024-10-28 01:37:05 +05:30
# Using Hardhat to Deploy Smart Contracts
2025-02-08 00:08:16 +05:30
This tutorial will guide you through the process of deploying a smart contract on Status Network testnet using Hardhat, Hardhat Ignition, and TypeScript.
2024-10-28 01:37:05 +05:30
## Prerequisites
Before you begin, ensure you have the following:
2025-02-08 00:08:16 +05:30
- **Node.js and npm**: Download and install from the [official Node.js website ](https://nodejs.org/ )
- **Ethereum Wallet**: MetaMask or another wallet with a private key for Status Network testnet
- **Testnet ETH**: You'll need Status Network testnet ETH
- Get Status Network testnet ETH from our [Faucet ](/tools/testnet-faucets )
- **Basic Knowledge**: Familiarity with Solidity, Hardhat, and command line
2024-10-28 01:37:05 +05:30
## What You'll Accomplish
2025-02-08 00:08:16 +05:30
- Initialize a TypeScript-based Hardhat project
- Write a basic Ethereum smart contract
- Configure Hardhat for Status Network testnet deployment
- Deploy your smart contract using Hardhat Ignition
2024-10-28 01:37:05 +05:30
## Steps
### 1. Initialize a Hardhat TypeScript Project
2025-02-08 00:08:16 +05:30
First, create and set up your project:
2024-10-28 01:37:05 +05:30
```bash
mkdir my-hardhat-project && cd my-hardhat-project
npm init -y
2025-02-08 00:08:16 +05:30
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
npx hardhat init
2024-10-28 01:37:05 +05:30
```
2025-02-08 00:08:16 +05:30
When prompted, select "Create a TypeScript project" to set up a TypeScript-based Hardhat project.
Set up your environment variables:
2024-10-28 01:37:05 +05:30
```bash
2025-02-08 00:08:16 +05:30
# Create a .env file
touch .env
# Add your private key (never commit this file!)
echo "PRIVATE_KEY=your_private_key_here" >> .env
2024-10-28 01:37:05 +05:30
```
### 2. Writing the Smart Contract
2025-02-08 00:08:16 +05:30
Create `contracts/HelloWorld.sol` :
2024-10-28 01:37:05 +05:30
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^ 0 . 8 . 24 ;
contract HelloWorld {
string public greet = "Hello, Status Network!" ;
function setGreet ( string memory _greet ) public {
greet = _greet ;
}
function getGreet () public view returns ( string memory ) {
return greet ;
}
}
```
### 3. Configuring Hardhat for Status Network
2025-02-08 00:08:16 +05:30
Update `hardhat.config.ts` :
2024-10-28 01:37:05 +05:30
```typescript
import { HardhatUserConfig } from "hardhat/config" ;
import "@nomicfoundation/hardhat-toolbox" ;
2025-02-08 00:08:16 +05:30
import * as dotenv from "dotenv" ;
dotenv . config ();
const PRIVATE_KEY = process . env . PRIVATE_KEY || "" ;
2024-10-28 01:37:05 +05:30
const config : HardhatUserConfig = {
2025-02-08 00:08:16 +05:30
solidity : "0.8.24" ,
2024-10-28 01:37:05 +05:30
networks : {
statusTestnet : {
2025-02-08 00:08:16 +05:30
url : "https://public.sepolia.rpc.status.network" ,
chainId : 1660990954 ,
accounts : [ PRIVATE_KEY ],
2024-10-28 01:37:05 +05:30
},
},
};
export default config ;
```
2025-02-08 00:08:16 +05:30
### 4. Create Ignition Deployment Module
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
Create `ignition/modules/HelloWorld.ts` :
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
```typescript
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules" ;
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
export default buildModule ( "HelloWorld" , ( m ) => {
const helloWorld = m . contract ( "HelloWorld" );
return { helloWorld };
});
```
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
### 5. Deploy the Contract
2024-10-28 01:37:05 +05:30
```bash
npx hardhat compile
2025-02-08 00:08:16 +05:30
npx hardhat ignition deploy ignition/modules/HelloWorld.ts --network statusTestnet
2024-10-28 01:37:05 +05:30
```
2025-02-08 00:08:16 +05:30
The deployment will create a new directory `ignition/deployments` containing your deployment artifacts and history.
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
### 7. Interact with Your Contract
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
Create `scripts/interact.ts` :
2024-10-28 01:37:05 +05:30
```typescript
import { ethers } from "hardhat" ;
2025-02-08 00:08:16 +05:30
import { HelloWorld } from "../typechain-types" ;
2024-10-28 01:37:05 +05:30
async function main() {
2025-02-08 00:08:16 +05:30
const contractAddress = "0x0d8a93870494Fa21ec39602f31Aa67C9Fed5604f" ;
2024-10-28 01:37:05 +05:30
const HelloWorld = await ethers . getContractFactory ( "HelloWorld" );
2025-02-08 00:08:16 +05:30
const contract = HelloWorld . attach ( contractAddress ) as HelloWorld ;
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
// Read current greeting
const greeting = await contract . getGreet ();
console . log ( "Current greeting:" , greeting );
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
// Update greeting
const tx = await contract . setGreet ( "Hello from Status Network!" );
2024-10-28 01:37:05 +05:30
await tx . wait ();
2025-02-08 00:08:16 +05:30
console . log ( "Greeting updated!" );
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
// Read updated greeting
const newGreeting = await contract . getGreet ();
console . log ( "New greeting:" , newGreeting );
2024-10-28 01:37:05 +05:30
}
main (). catch (( error ) => {
console . error ( error );
process . exitCode = 1 ;
});
```
2025-02-08 00:08:16 +05:30
Run the interaction script:
2024-10-28 01:37:05 +05:30
```bash
npx hardhat run scripts/interact.ts --network statusTestnet
```
2025-02-08 00:08:16 +05:30
## Support
2024-10-28 01:37:05 +05:30
2025-02-08 00:08:16 +05:30
If you encounter any issues:
2025-02-20 01:59:12 +05:30
- Join our [Telegram Community ](https://t.me/statusl2 )
2025-02-08 00:08:16 +05:30
- View our [Network Details ](/general-info/network-details )