0% found this document useful (0 votes)
18 views17 pages

Smart Contracts

The document provides an overview of smart contracts, specifically focusing on their implementation using the Solidity programming language. It covers the definition of smart contracts, the structure of Solidity, its history, data types, function types, and deployment steps. Additionally, it includes a sample program and highlights key properties of Solidity, such as being contract-oriented and statically typed.

Uploaded by

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

Smart Contracts

The document provides an overview of smart contracts, specifically focusing on their implementation using the Solidity programming language. It covers the definition of smart contracts, the structure of Solidity, its history, data types, function types, and deployment steps. Additionally, it includes a sample program and highlights key properties of Solidity, such as being contract-oriented and statically typed.

Uploaded by

kpu21195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

SMART

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

• Constructor-Executed only once when the contract is deployed


• fallback(),receive()- Handles direct ether transfers.
• View-Reads state but does not modify it 7
Sample
program
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract NumberStorage {
uint256 private storedNumber;

function setNumber(uint256 _number) public {


storedNumber = _number;
}

function getNumber() public view returns (uint256) {


return storedNumber;
} 8

}
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

Fig1 : Creating folder and initializing truffle init. 11


Fig2 : the folder created

Use any text editor

12
• compile the contract using -truffle compile
• deploy the contract to ganache using -truffle migrate --reset

13
• Contract is deployed in ganache.

• Interact with contract using -truffle console


• copy the instance of the deployed contract to a variable instance.
• call functions setNumber() for input and getNumber() for output

14
15
16
THANKYOU

17

You might also like