Ref - https://www.anchor-lang.com/docs/basics/program-structure

Screenshot 2025-05-16 at 7.15.20 PM.png

declare_id! macro

The declare_id macro specifies the on-chain address of the program, known as the program ID.

use anchor_lang::prelude::*;
 
declare_id!("11111111111111111111111111111111");

#[program] attribute

The #[program] attribute annotates the module containing all the instruction handlers for your program. Each public function within this module corresponds to an instruction that can be invoked.

Screenshot 2025-05-16 at 7.16.37 PM.png

This makes our solana contract closer to a solidity contract

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

contract Calculator {
    uint64 data;
    function initialize(uint64 _data) public {
        data: _data        
    }
}

#[derive(Accounts)] macro

The #[derive(Accounts)] macro is applied to a struct to specify the accounts that must be provided when an instruction is invoked. This macro implements the Accounts trait, which simplifies account validation and serialization and deserialization of account data.

Screenshot 2025-05-16 at 7.19.38 PM.png

Screenshot 2025-05-16 at 7.20.16 PM.png

When an instruction in an Anchor program is invoked, the program first validates the accounts provided before executing the instruction's logic. After validation, these accounts can be accessed within the instruction using the ctx.accounts syntax.

#[account] attribute

The #[account] attribute is applied to structs that define the structure of the data stored in custom accounts created by your program.

#[account]
pub struct NewAccount {
    data: u64,
}