0% found this document useful (0 votes)
24 views4 pages

Solidity Notes Exam Ready

Solidity is a contract-oriented programming language for writing smart contracts on Ethereum and EVM-compatible blockchains, with a syntax similar to JavaScript/C++. Key concepts include data types, visibility modifiers, function modifiers, and error handling, along with examples of contract structure and deployment. It is used in various applications such as voting and crowdfunding, with important security practices to follow.

Uploaded by

adityansut613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Solidity Notes Exam Ready

Solidity is a contract-oriented programming language for writing smart contracts on Ethereum and EVM-compatible blockchains, with a syntax similar to JavaScript/C++. Key concepts include data types, visibility modifiers, function modifiers, and error handling, along with examples of contract structure and deployment. It is used in various applications such as voting and crowdfunding, with important security practices to follow.

Uploaded by

adityansut613
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Solidity Complete Notes for Exam

1. What is Solidity?

Solidity is a high-level, contract-oriented programming language used for writing smart contracts on

Ethereum and other EVM-compatible blockchains. It has syntax similar to JavaScript/C++ and

compiles to bytecode for the Ethereum Virtual Machine (EVM).

2. Structure of a Solidity Contract

Example:

pragma solidity ^0.8.0;

contract MyContract {

uint public myNumber;

function set(uint _num) public {

myNumber = _num;

function get() public view returns (uint) {

return myNumber;

3. Data Types

- uint, int: Unsigned/signed integers

- address: Ethereum wallet address

- bool: Boolean

- string: Text string


- bytes: Byte arrays

4. Visibility Modifiers

- public: Anyone can access

- private: Only within the contract

- internal: Within contract and derived

- external: Callable externally only

5. Function Modifiers

- view: Reads state

- pure: Does not read or write state

- payable: Accepts Ether

Example of custom modifier:

modifier onlyOwner() {

require(msg.sender == owner, 'Not authorized');

_;

6. Important Keywords

- msg.sender: Caller address

- msg.value: Ether sent

- require(): Validates conditions

- emit: Logs events

- constructor: Runs once at deployment

7. Storage Types

- storage: Permanent

- memory: Temporary

- calldata: Immutable input

8. Events
Used for logging. Example:

event Transfer(address indexed from, address indexed to, uint amount);

9. Inheritance

Solidity supports inheritance.

Example:

contract A {

function sayHi() public pure returns (string memory) { return 'Hi'; }

contract B is A {}

10. Error Handling

- require(condition, 'error')

- assert(condition)

- revert('message')

11. Constructor

Runs once on contract deployment.

Example:

constructor() { owner = msg.sender; }

12. Modifiers

Access control modifiers like onlyOwner to protect functions.

13. Deploying Contracts

Use tools like Remix, Truffle, Hardhat. Needs Ether for gas.

14. Use Cases

- Voting, Crowdfunding, Supply Chain, Token Creation

15. Security Tips

- Use latest compiler, avoid tx.origin, protect against reentrancy


Memory Hooks

SCFVD: Smart Contract, Functions, Visibility, Data Types

RVP: Require, View, Payable

MSG: msg.sender, msg.value, gas

PEM: Pragma, Events, Modifiers

Exam Writing Tip

Start with definition, include one code example, structure with headings, add a conclusion.

You might also like