0% found this document useful (0 votes)
8 views

BC 106 Lecture 2

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)
8 views

BC 106 Lecture 2

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
You are on page 1/ 39

BC 106

LECTURE 2
Presented By : Akshat, Reeshabh
BlocSoc IITD
IIT Delhi| 2024
ETHEREUM
•Developed by Vitalik Buterin
•Decentralized, open-source blockchain platform that enables
the creation of smart contracts and decentralized applications
(dApps).
•It uses its own cryptocurrency called Ether (ETH) to power
transactions.
•Allows developers to build and deploy programmable contracts
without needing third-party involvement.
SMART CONTRACTS
•The term was first coined by Nick Szabo in 1997.
•A smart contract is a self-executing contract with
the terms directly written into code. It
automatically enforces and processes transactions
when predefined conditions are met, without
needing a middleman like a courts or bank.
•Transition from paper agreements to
cryptographic agreements.
SMART CONTRACTS
•Brings transparency, immutability and speed.
•Examples :
•Insurance against flight delays.
•Freelancer Payment
•Crowdfunding
THE ORACLE PROBLEM
•The challenge of getting real-
Dependency on oracles -->
world data (like weather reports,
Third-party services feed external
stock prices, or flight information into smart contracts -
information) into a blockchain -> Decentralization and security
system, which is designed to be ???

self-contained and trustless.


HYBRID SMART CONTRACTS
Combine the benefits of both traditional smart contracts and off-chain resources.
1

They consist of two parts: smart contract code that runs on the blockchain, and
2 decentralized oracle networks (DONs) that provide secure off-chain services.

Chainlink is a popular decentralized oracle network that sources data from many
3 providers, ensuring no single oracle can corrupt the data.
METAMASK
Overview
MetaMask is a cryptocurrency wallet used to interact with the Ethereum
blockchain.

Link
https://metamask.io
DECENTRALISED
APPS
1

CRYPTOCURRENCY EXCHANGE
2

Traders Exchange
3
4
5
6
ADVANTAGES
Autonomy - No single authority controls a dapp

Open Source - Immutable


Transparency
8
EXAMPLES
6
DISADVANTAGES
Scalability

Cost
REMIX IDE AND SOLIDITY
Remix IDE Link
Solidity is a programming
https://remix.ethereum.org language for implementing
smart contracts on various
Used for compiling and blockchain platforms, most
deploying smart contracts notably, Ethereum.
SOLIDITY
Trust in smart contracts can be better
established if their source code is available.
Since making source code available always
touches on legal problems with regards to
copyright, the Solidity compiler encourages
the use of machine-readable SPDX license
identifiers.
SOLIDITY
The pragma keyword is used to enable certain
compiler features or checks.
Source files can (and should) be annotated
with a version pragma to reject compilation
with future compiler versions that might
introduce incompatible changes
SOLIDITY COMPILATION
Bytecodes ABI
Bytecode is a software computer language for ABIs are application binary
instruction-level programming. It is the interfaces. They define the
information that the Solidity code gets methods and variables that are
translated into. It contains instructions to the available in a smart contract and
computer in binary form. which we can use to interact with
Each instruction step in bytecode is an that smart contract.
operation that is referred to as opcode.
Opcodes are 1-byte long. This is the reason
they are called bytecodes
GAS
When a smart contract is compiled in Solidity, it is converted into a
series of "operation codes," also referred to as opcodes. Each
opcode is given a predefined amount of gas, which represents the
computing work necessary to carry out that specific operation.
Every time we update the state of blockchain, it is going to cost gas.

Checking balance : 400 gas


Transaction : 21,000 gas

Transaction fee = gas price * total gas


VARIABLES
Local Variables
Local variables are declared within a function and can only be accessed
within that function. They exist only during the execution of the function
and are destroyed once the function execution is complete.

Global Variables
Global variables are predefined and accessible from any function
within the contract.
VISIBILITY SPECIFIERS
View functions
Can only read form the blockchain but cannot modify anything

Pure functions
Can neither read from nor modify the blockchain
VALUE TYPES
Booleans Solidity is a statically typed
bool: The possible values are
language, which means that the
constants true and false.
type of each variable (state and
local) needs to be specified.

Integers
int / uint: Signed and unsigned
integers of various sizes.
Keywords uint8 to uint256 in
steps of 8 (unsigned of 8 up to
256 bits) and int8 to int256.
VALUE TYPES
Address
Holds a 20 byte value (size of an
Ethereum address).

Fixed-size byte
The value types bytes1, bytes2,
bytes3, …, bytes32 hold a
sequence of bytes from one to up
to 32.
REFERENCE TYPES
String Struct
Strings are like arrays of Solidity allows users to create and
characters. define their own type in the form of
structures.

Arrays Mappings
Stores the data in a key-value pair
An array is a group of variables of
where a key can be any value type. It is
the same data type in which the
like a dictionary as in any other
variable has a particular location
known as an index programming language, where data
can be retrieved by key.
DATA LOCATIONS
Memory
Used for functional arguments and local variables.

Calldata
Used for functional arguments and local variables but are read-only.

Storage
Used to permanently store data on blockchain.

Data locations are specified only for arrays, mappings and structs.
CONSTRUCTORS
A constructor is a special function that gets executed once when
a smart contract is deployed. It’s typically used to initialize the
contract's state variables or set up initial values.
REQUIRE AND REVERT
Require
The require function is a condition-checking mechanism. It ensures that specific
conditions are met before executing further logic in the smart contract.
require( condition , "Error to be shown");

Revert
The revert statement is used to manually trigger an exception. It undoes
all the changes made to the contract state and allows developers to
return a reason for reverting the transaction.
if (condition) {
revert("Error to be shown");
}
GLOBAL KEYWORDS
Keywords that provide information about the blockchain state and
the current transaction

msg.data msg.sender

msg.sig msg.value

tx.gasprice tx.origin
Transacting Ether using a contract
Gas Error
Function Recommended Use
Forwarded Handling

transfer 2300 Reverts on failure Safe, simple Ether transfers

Returns false on Rarely used, manual error


send 2300
failure handling required

All remaining Returns false on Flexible for sending Ether or


call (unless specified) failure interacting with contracts
LIBRARIES
Libraries are similar to contracts but certain actions can’t be
performed in it . Example :
A state variable can’t be declared
Ether can’t be sent or received

A library is embedded in a contract only if all the library


functions are internal and the library is deployed before the
contract.
INTERFACE
An interface in Solidity is a contract that defines a set of
functions without providing any implementation.
All functions in the interface are implicitly declared as
external.
Interfaces cannot have constructors.
Interfaces cannot have state variables.
A contract can inherit from multiple interfaces, but must
implement all the required functions.
ABSTRACT CONTRACTS
An abstract contract is a contract that contains at least one
function without an implementation.
Abstract contracts can have constructors.
Abstract contracts can have state variables.

Other contracts inheriting from an abstract contract must


implement all the unimplemented functions, or they will also be
considered abstract.
DEPLOYING A CONTRACT
FROM ANOTHER CONTRACT
INHERITENCE AND
OVERRIDING
IIT Delhi

THANK YOU
Presented By : Akshat, Reeshabh
BlocSoc IITD

You might also like