BC 106 Lecture 2
BC 106 Lecture 2
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 ???
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
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.
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
THANK YOU
Presented By : Akshat, Reeshabh
BlocSoc IITD