Courses

Building Your First Smart Contract on Polygon
Polygon · Chapter 6

Building Your First Smart Contract on Polygon

This small contract stores a number and lets anyone increase it by one. It does not hold funds or require an owner, making it a useful learning example.

The basics

  • Paste the code into Counter.sol in Remix and compile with a compatible 0.8.x compiler.
  • In Deploy & Run, select Remix VM, choose Counter and deploy it to the simulation.
  • Click count to read zero. Click increment, then count again: the value should be one. Public creates a getter; external makes increment callable from outside.

Small example

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

contract Counter {
    uint256 public count;

    function increment() external {
        count += 1;
    }
}

Try it yourself

Increment twice more and read the result. Deploy a second copy and check its count: each deployment has its own state.

Read more in the official documentation

@ Daniel Burlacu