This document provides an overview and introduction to writing smart contracts with Solidity on the Ethereum blockchain. It discusses key concepts like how blockchains and Ethereum work, what smart contracts are, and how to use tools like Remix and Ganache for writing, testing, and deploying smart contracts. It also covers Solidity basics like data types, functions, inheritance, and more.
The presentation introduces Ethereum and Smart Contracts, highlighting Solidity as the programming language with details on functionality, transaction validation, and the digital nature of agreements.
Focus on the Solidity language, its features, and tools like Remix IDE for writing, testing, and deploying smart contracts.
Key programming concepts in Solidity such as memory storage, variable types, data types, functions, inheritance, and modifiers, crucial for smart contract development.
Demonstrates using tools like Ganache and Metamask for deploying contracts on local and test networks, engaging in practical projects and learning resources.
• Agreements arewritten as Smart
Contracts.
• Smart Contracts are business
logic
• Transactions are validated
against Smart Contract
Smart Contract
8.
• Digitized andcodi
fi
ed rules of
transaction between accounts
• In Ethereum world smart
contracts are written in language
called Solidity and deployed into
Ethereum network
Smart Contract
Solidity – Languageto write Smart Contract
• Solidity is a contract-oriented, high-level language for implementing smart
contracts.
• It was in
fl
uenced by C++, Python and JavaScript and is designed to target the
Ethereum Virtual Machine (EVM).
• Solidity is statically typed, supports inheritance, libraries and complex user-
de
fi
ned types among other features.
• Written in .sol
fi
les
Web browser basedIDE
• Write Solidity smart contracts
• Test smart contract
• Deploy
• Run the smart contracts.
Remix web tool
14.
Write & compile
HelloWorld
programin Remix
Use memory storage For return struct or array
types of data is good practice and it improves
the performance of code and from solidity
version 0.5.0, it is compulsory to use memory
storage for this type of data types.
Comments
• Single-line commentsare denoted by a double forward slash //,
• Multiline comments are denoted using /* and */.
• Natspec has two formats: ///
State variables
• Variablesin programming refer to storage location that can contain values.
These values can be changed during runtime.
• State variables that are permanently stored in a blockchain/Ethereum ledger
by miners.
• State variables store the current values of the contract.
• The allocated memory for a state variable is statically assigned and it cannot
change (the size of memory allocated) during the lifetime of the contract.
20.
State variable access
•internal: This variable can only be used within current contract functions and
any contract that inherits from them.
• int internal StateVariable;
• private
• int public stateIntVariable;
• constant: This quali
fi
er makes state variables immutable.
• bool constant hasIncome = true;
21.
Data types
• bool
• uint/int
• bytes
• address
• mapping
• key-value table
(keccak256 hash)
• enum
• user-de
fi
ned type
• struct
• Bytes/String
Function Types
• public- Anyone can call this function
• private - Only this contract can call this function.
• view - This function returns data and does not modify the contract's data
• constant - This function returns data and does not modify the contract's data
• pure - Function will not modify or even read the contract's data
• payable - When someone call this function they might send ether along
24.
• Solidity supportsdeclaring a
constructor within a contract.
• Constructors are optional in
Solidity and the compiler induces
a default constructor when no
constructor is explicitly de
fi
ned.
• The constructor is executed
once while deploying the
contract.
Constructors
25.
• In Solidity,a modi
fi
er is always
associated with a function.
• A modi
fi
er in programming
languages refers to a construct
that changes the behavior of the
executing code.
Modifier
Inheritance
• Solidity supportsinheritance between smart contracts.
• Inheritance is the process of de
fi
ning multiple contracts that are related to
each other through parent-child relationships.
• Solidity supports multiple types of inheritance, including multiple inheritance.