Getting started

Your first contract

A counter, in both worlds. A NEAR contract is a Rust struct plus an impl block — the fields are storage, the methods are your ABI.

In Solidity a contract is a contract block: state variables at the top, functions below. On NEAR a contract is a Rust struct that holds the state, plus an `impl` block whose public methods are the callable interface.

The #[near(contract_state)] macro marks the struct as the contract’s persisted state. #[near] on the impl exposes its pub methods as contract calls and generates the (de)serialization glue.

A counter contract
Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Counter {
    uint256 public count;

    function increment() external {
        count += 1;
    }
}
Rust
use near_sdk::near;

#[near(contract_state)]
#[derive(Default)]
pub struct Counter {
    count: u64,
}

#[near]
impl Counter {
    pub fn increment(&mut self) {
        self.count += 1;
    }

    pub fn get_count(&self) -> u64 {
        self.count
    }
}
Coming from EVM

A method that writes takes &mut self; one that only reads takes &self. That receiver is the whole story — there is no external / public / view keyword.

Solidity’s public state variable auto-generates a getter. NEAR does not: if you want to read count from outside, you write an explicit &self view method (get_count).