Example Counter on Nexus

To learn how to build and deploy an app on Nexus, take a look at the demo project below:

Overview

This project demonstrates a basic integration between a web application and the Nexus blockchain. It features a smart contract that maintains a counter which can only be incremented, showcasing fundamental blockchain interactions like:

  • Smart contract deployment

  • Wallet connection

  • Transaction signing

  • Event listening

  • State updates

The Smart Contract

You will learn how to deploy the following smart contract counter on Nexus:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
    uint256 private count;
    
    event CountIncremented(uint256 newCount);
    
    function increment() public {
        count += 1;
        emit CountIncremented(count);
    }
    
    function getCount() public view returns (uint256) {
        return count;
    }
}

Project Structure

The project is separated into two packages:

  • contracts: A Hardhat project for deploying Counter.sol on Nexus

  • frontend: A NextJS project for interacting with Counter.sol on Nexus

nexus-counter/
├── contracts/
│   └── contracts/
│       └── Counter.sol
├── frontend/
│   ├── pages/
│   │   └── index.tsx
│   └── package.json
└── package.json

We will share more end-to-end guides in the future.