Browse DIDLab Docs

Deployment · Hardhat

Compile locally and deploy to DIDLab

This public workflow uses Hardhat for compilation and a small ethers deployment script for the remote DIDLab transaction. It keeps the example transparent and avoids hiding deployment behavior behind a large project template.

01

Create a local project

Use a current Node.js development environment and a dedicated lab wallet. Create a project, initialize npm, and install Hardhat plus ethers.

Terminal
mkdir didlab-simple-storage
cd didlab-simple-storage
npm init -y
npm pkg set type=module
npm install --save-dev hardhat
npm install ethers

Wallet safety

The scripted path needs a private key because it signs from your local workstation. Use only a disposable DIDLab lab wallet and never reuse a personal wallet key.
02

Initialize Hardhat and add the contract

Initialize a minimal Hardhat project, then place the contract below at contracts/SimpleStorage.sol.

Initialize
npx hardhat --init
contracts/SimpleStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract SimpleStorage {
    uint256 private value;
    event ValueChanged(uint256 value, address indexed changedBy);

    function set(uint256 newValue) external {
        value = newValue;
        emit ValueChanged(newValue, msg.sender);
    }

    function get() external view returns (uint256) {
        return value;
    }
}
03

Compile locally

Compile
npx hardhat compile

Expected result

Hardhat creates an artifact for SimpleStorage under artifacts/contracts/SimpleStorage.sol/. The deployment script below reads that ABI and bytecode.
04

Create the deployment script

Create scripts/deploy.mjs with the following example.

scripts/deploy.mjs
import fs from "node:fs";
import { ethers } from "ethers";

const rpcUrl = process.env.DIDLAB_RPC_URL;
const privateKey = process.env.DIDLAB_PRIVATE_KEY;

if (!rpcUrl || !privateKey) {
  throw new Error("Set DIDLAB_RPC_URL and DIDLAB_PRIVATE_KEY first.");
}

const artifact = JSON.parse(
  fs.readFileSync("./artifacts/contracts/SimpleStorage.sol/SimpleStorage.json", "utf8")
);

const provider = new ethers.JsonRpcProvider(rpcUrl);
const wallet = new ethers.Wallet(privateKey, provider);
const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode, wallet);

console.log("Deployer:", wallet.address);
const contract = await factory.deploy();
await contract.waitForDeployment();

const address = await contract.getAddress();
const deploymentTx = contract.deploymentTransaction();
console.log("Contract:", address);
console.log("Deployment tx:", deploymentTx?.hash);

const tx = await contract.set(42);
const receipt = await tx.wait();
console.log("set(42) tx:", receipt?.hash);
console.log("get():", (await contract.get()).toString());
05

Set credentials without committing them

Set the DIDLab RPC URL and your disposable lab wallet key in the current shell. Do not put the key in source control.

Linux/macOS shell
export DIDLAB_RPC_URL=https://eth.didlab.org
export DIDLAB_PRIVATE_KEY='0xYOUR_DISPOSABLE_LAB_PRIVATE_KEY'
node scripts/deploy.mjs

Before deploying

Make sure the deployer wallet already has enough TRUST for gas. Use the DIDLab Faucet & Funding page if it needs a small lab balance.
06

Verify the output

The script prints the deployer address, contract address, deployment transaction hash, the set(42) transaction hash, and the final get() value. Search the addresses and hashes in Blockscout.

Open DIDLab Explorer

Public guide complete

At this point you have a reproducible source → compile → deploy → interact → verify workflow. The DIDLab Labs version extends this into testing, deployment automation, event validation, debugging, security analysis, and evidence capture.

Validation profile

Network

DIDLab Blockchain

Chain ID

252501

Client

Hyperledger Besu

Consensus

QBFT

Native asset

TRUST

Platform token

TT (ERC-20)

Solidity examples

0.8.24

Last validated

August 2026

Go deeper in DIDLab Labs

Public documentation explains the workflow and expected result. Authenticated DIDLab Labs adds managed workspaces, deeper exercises, checkpoints, evidence capture, and instructor assessment.

Open DIDLab Labs