1. Home
  2. /
  3. Hardhat
  4. /
  5. Listen to Events

Listen to Events - Hardhat Typing CST Test

Loading…

Listen to Events — Hardhat Code

Listen to events emitted by a contract using Hardhat provider.

async function main() {
	const Counter = await ethers.getContractFactory('Counter')
	const counter = await Counter.attach('0xYourContractAddress')
	counter.on('Incremented', (newValue) => {
		console.log('Counter incremented to:', newValue)
	})
}

main().catch((error) => { console.error(error); process.exitCode = 1 })

Hardhat Language Guide

Hardhat is a JavaScript/TypeScript-based Ethereum development environment and framework. It enables developers to compile, deploy, test, and debug smart contracts efficiently on Ethereum and EVM-compatible networks.

Primary Use Cases

  • ▸Compiling and deploying Solidity smart contracts
  • ▸Running local Ethereum test networks
  • ▸Automated testing of smart contracts
  • ▸Debugging and logging transactions
  • ▸Scripted contract interactions and deployments

Notable Features

  • ▸Local development network (Hardhat Network)
  • ▸Solidity compilation and artifact management
  • ▸JavaScript/TypeScript-based scripting
  • ▸Plugin system for extended functionality
  • ▸Integration with ethers.js, web3.js, and Waffle

Origin & Creator

Hardhat was created by Nomic Labs in 2018 to simplify Ethereum smart contract development and provide a powerful local blockchain testing environment.

Industrial Note

Hardhat is preferred for Ethereum development workflows, CI/CD smart contract testing, automated deployment, and integration with frontends or other tools like ethers.js and web3.js.

More Hardhat Typing Exercises

Hardhat Minimal Smart Contract DeploymentHardhat Call Contract FunctionHardhat Get AccountsHardhat Estimate GasHardhat Deploy with ParametersHardhat Read Contract VariableHardhat Transfer EtherHardhat Deploy Multiple ContractsHardhat Upgradeable Contract Deployment

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher