Smart Contracts
Smart Contracts
CONTRACTS
USING
SOLIDITY
Krishna priya
U
S8 CSE
Smart
contracts
A smart contract is a self-executing contract with the terms of the
agreement directly written into code. It operates on a blockchain
network and automatically enforces and executes predefined rules when
specific conditions are met, without requiring intermediaries.
C=(S,I,T,O)
where:
• S=Set of possible states of the contract.
• I= Set of inputs (transactions) that trigger state transitions.
• T= State transition function, which determines how inputs modify the
contract state.
• O= Output function, which defines the response or actions performed
by the contract. 2
SOLIDIT
• Primary language for writing smart contracts on Ethereum
•
Y
Can also be used in other EVM compatible blockchains.
(Polygon,Avalanche)
• Solidity is a statically typed, contract-oriented programming language.
• Similar to JavaScript, but optimized for Ethereum Virtual Machine (EVM).
• Used to create smart contracts for DeFi, NFTs, DAOs, and Web3 apps
HISTORY
• Created in 2014 by Gavin Wood and maintained by the Ethereum
Foundation
• Inspired by JavaScript, C++, and Python.
• Widely used today for DeFi, NFTs, DAOs, and EVM-compatible blockchains
like BSC, Polygon, and Avalanche. 3
Data
Solidity has value types and reference types.
types
1.Value Types.
• Used for simple data, stored directly in
memory.
• Changing a variable creates a new copy.
4
2.Reference types
• Used for complex data structures.
• Stored in storage or memory.
• Changing a variable affects the original
data.
5
Functio
n
Functions are blocks of code that define the logic of smart contracts.
There are different functions based on visibility, payability andstate
modifications.
Function Visibility Types
6
Function
modifiers
Used to add security checks and reusable logic before function
execution
contract NumberStorage {
uint256 private storedNumber;
}
Properties
• Contract oriented- Contract defines rules for ownership, transactions and
interactions
• Statically typed- All variables must have a declared type. This prevents
type errors at compile time.
• Supports Inheritance .
• Uses modifiers and Libraries for code reusability.
• It supports events, to store logs on the blockchain.
• Ethereum specific features (address type, blockchain state)
• Multiple ways to handle errors securely.(require(),revert())
• Cross Blockchain compatibility.
9
Steps to
• deploy
Create a project and initialize Truffle
• In contracts/, create a new file filename.sol and paste the contract
code.
• Compile the contract
• Create a .js file in migrations.
• Start Ganache and deploy the contract.
• Open Truffle console and interact with the contract.
10
Create
Create a project
a project and initialize
and initialize Truffle
12
• compile the contract using -truffle compile
• deploy the contract to ganache using -truffle migrate --reset
13
• Contract is deployed in ganache.
14
15
16
THANKYOU
17