Skip to main content
Use this guide when you want to set up Hardhat with Viem for Berachain, deploy a simple contract, verify it on the block explorer, and optionally run a local Hardhat node and tests.

Repository

Requirements

Stack

Hardhat, Viem, Solidity, TypeScript.

Quick start

  1. Clone and install
    git clone https://github.com/berachain/guides.git && cd guides/apps/hardhat-viem-helloworld
    npm install
    cp .env.example .env
    
    Set WALLET_PRIVATE_KEY in .env.
  2. Compile and deploy to Berachain testnet
    npm run compile
    npm run deploy:berachain
    
    (Uses scripts/deploy.ts and network berachainTestnet.)
  3. Verify on block explorer
    npm run verify <DEPLOYED_ADDRESS> "Hello From Deployed Contract"
    
  4. Optional — local node: npm run node in one terminal, then npm run deploy:localhost in another.
  5. Run tests: npm run test

Key files

PurposePath
Contractcontracts/HelloWorld.sol
Deploy scriptscripts/deploy.ts
Teststest/HelloWorld.test.ts