0x0878342730E6d6695e9aD2e5B81bEDc138cb3F7A
Explorer: https://coston2-explorer.flare.network/address/0x0878342730E6d6695e9aD2e5B81bEDc138cb3F7A
HealthCheck is a minimal on-chain contract and frontend integration that enables a single owner address to publish a simple health status and a human-readable message on the blockchain. The contract exposes a small set of functions to read the current status (as an enum), the message, the owner, and a timestamp of the latest update. The owner can update the status and message, as well as transfer ownership to another address.
This repository contains:
- A typed ABI and contract address binding (
lib/contract.ts) for use with viem/wagmi. - A React hook (
hooks/useContract.ts) that encapsulates reading and writing to the HealthCheck contract, handling loading, pending, confirmations, and errors. - A sample UI component (
components/sample.tsx) demonstrating how to display contract state and provide owner-only controls to update status and transfer ownership.
The stack is focused on modern Ethereum tooling: wagmi for hooks and transactions, viem types for addresses, and a React/Next.js client-side component model.
- Read current health status (enum) and message from-chain.
- Display contract owner and last update timestamp.
- Owner-only UI controls to:
- Update the health status (Unknown, Healthy, Degraded, Unhealthy).
- Publish a short human-readable message about the state.
- Transfer ownership to another address.
- Robust UX:
- Wallet gating (prompts user to connect wallet).
- Clear loading/pending/confirmation states.
- Error handling and transaction feedback (hash, confirming, confirmed).
- Minimal, easy-to-understand code suitable for beginners and as a template for building more advanced on-chain status/monitoring systems.
Many decentralized and distributed systems require a transparent, tamper-resistant way to communicate service or system health. HealthCheck provides a straightforward pattern for publishing service health data on-chain:
- Public, auditable status: The health status and messages are recorded on the blockchain, ensuring transparency and immutability. Anyone can verify the latest reported state and who reported it.
- Permissioned updates: Only the contract owner (typically the operator or an automated on-chain agent) may update the status, preventing arbitrary actors from spoofing system state.
- Simple integration: The included React hook and sample UI demonstrate how to integrate contract reading and writing into a web interface, showing best-practice handling of async transaction lifecycle.
- Use cases:
- Decentralized services reporting uptime or degradations.
- Oracles or monitors publishing quick alerts.
- DAO-operated infrastructure status boards.
- Any project needing a compact on-chain "noticeboard" for status and short messages.
- Contract ABI: Included under
lib/contract.tsas aconsttuple for use withviem/wagmi. - Primary functions:
getStatus() -> (uint8 status, string message, address owner, uint256 timestamp)— read consolidated state.updateStatus(uint8 _status, string _message)— owner-only; update status and message.transferOwnership(address newOwner)— owner-only; change controlling address.
- Enums: Status enum mapping used in UI:
0 = Unknown1 = Healthy2 = Degraded3 = Unhealthy
- Ensure your project has
wagmiandvieminstalled and configured for the Coston2/Flare testnet (or appropriate provider). - Place the
lib/contract.tsfile into your codebase and confirm thecontractAddressmatches0x0878342730E6d6695e9aD2e5B81bEDc138cb3F7A. - Import the hook:
import { useHealthCheckContract } from "@/hooks/useContract"