LibChain Docs Lib Testnet

Build

Deploy with Hardhat

Add Lib Testnet to a Hardhat project, deploy with a script or Ignition, and interact with contracts from the console.

Hardhat talks to LibChain over standard JSON-RPC. This guide uses Hardhat 2 with @nomicfoundation/hardhat-toolbox; the network settings are the same in Hardhat 3.

#Configure

Terminal
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
npx hardhat init
hardhat.config.ts
import 'dotenv/config'
import type { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'

const config: HardhatUserConfig = {
  solidity: {
    version: '0.8.28',
    settings: { evmVersion: 'cancun', optimizer: { enabled: true, runs: 200 } },
  },
  networks: {
    libTestnet: {
      url: 'https://rpc-testnet.libchain.tech',
      chainId: 54210,
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    },
  },
}

export default config
.env
PRIVATE_KEY=0x...   # a testnet-only key; add .env to .gitignore

#Deploy with a script

scripts/deploy.ts
import { ethers } from 'hardhat'

async function main() {
  const counter = await ethers.deployContract('Counter')
  await counter.waitForDeployment()
  console.log('Counter deployed at', await counter.getAddress())
}

main().catch((e) => { console.error(e); process.exitCode = 1 })
Terminal
npx hardhat run scripts/deploy.ts --network libTestnet

#Deploy with Ignition

ignition/modules/Counter.ts
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'

export default buildModule('CounterModule', (m) => {
  const counter = m.contract('Counter')
  m.call(counter, 'setNumber', [1n])
  return { counter }
})
Terminal
npx hardhat ignition deploy ignition/modules/Counter.ts --network libTestnet

Ignition waits for confirmations between steps. On LibChain one confirmation is final, so the defaults only add a little waiting.

#Use the console

Terminal
npx hardhat console --network libTestnet
TypeScript
const wtlib = await ethers.getContractAt(['function totalSupply() view returns (uint256)'], '0x87052f1f17b2b4054b014e93e53d6ce6dc912bda')
ethers.formatEther(await wtlib.totalSupply())

hardhat-verify needs a verification backend, which isn't enabled on Lib Testnet yet. See Verify a contract.

Updated 5 November 2026LibChain Docs · Lib Testnet