Explore an example Counter application built using the Nexus Layer 1
hardhat.config.js
which will define the network configuration, RPC endpoint for Hardhat to connect to, and chainID for signature verification:
.env
in your project root directoryhardhat.config.js
if not already present:contracts/Counter.sol
:
This contract is a basic stateful Solidity example for learning blockchain development. It demonstrates essential concepts such as modifying contract storage, emitting events, and exposing read-only and state-changing functions.
The contract implements a simple counter. When deployed, it starts at zero and exposes a method to increment the count. Each increment emits an event with the new value, allowing external apps or frontends to react to on-chain activity.
This type of contract is useful for:
uint256
variable. Making it private ensures that external contracts can’t modify or read it directly—access is only possible through the exposed functions.
getCount()
repeatedly.
increment()
getCount()
view
function, so it doesn’t consume gas when called from off-chain. It gives the frontend a way to fetch the latest state directly from the blockchain.
getCount
)increment
)CountIncremented
)scripts/deploy.js
:
A deployment script is a programmatic way to deploy your smart contracts to a blockchain using Hardhat. Instead of manually interacting with the network through a UI or console, deployment scripts allow you to:
ether.js
in your Next.js project:
src/app/page.tsx
file to integrate the deployed smart contract with the frontend:
contracts
: A Hardhat project for deploying Counter.sol
on Nexus
frontend
: A NextJS project for interacting with Counter.sol
on Nexus
frontend/src/app/page.tsx
file.