3. A non-profit developers group to
develop, learn and share.
Who Are We?
Google Developer Student
Clubs - JSSSTU
4. Currently (in 2021), head of the department of
Computer Science and Engineering, with nearly three
decades of teaching experience. Driven by the motto,
“Anything worth doing is worth doing well,” to create a
challenging and engaging learning environment for
students and self. Her research focuses mainly on
Machine Learning and Healthcare Informatics with a
particular emphasis on the applications of healthcare
technology to socially relevant issues.
Our Faculty Advisor
Dr. M P Pushpalatha
7. These three phases are not based on what technologies are used, rather they
explain how the web is being used.
Web 1.0
Web 1.0 vs Web 2.0 vs Web 3.0
Web 2.0 Web 3.0
(Read) (Read,Write) (Read,Write,Own)
8. Chain of blocks linked
through cryptographic
hash function.
Blockchain Architecture
9. Let’s have a demonstration of working of hash function and blockchain.
Head over to-
bit.ly/bc-block-demo
Demo
15. How blocks are verified?
Consensus Model: Procedure through which all the peers of the Blockchain
network reach a common agreement about the present state of the Distributed
Network.
Ex: Proof of Work
Blockchain Architecture
How blocks are added?
Mining: Process of adding new block to the blockchain network
Verify, Verify, Verify… But who does that….? And How?
16. Blockchain Architecture
● Highly secure
● Difficult to hack the system
● Transparent
Block… Blockchain, Main jukega nahi!
● Very less or almost zero downtime
Conclusions:
17. Application Devs
(Web3.0 & Smart Contracts)
➔ Solidity
➔ JavaScript
➔ Python
[>90%]
Blockchain Developers
Core Devs
(Architecture)
➔ Go
➔ C++
➔ Rust
[very less]
Blockchain Development
21. - Ethereum is a decentralized, open-source
blockchain with smart contract functionality
- Founded in 2013 - Vitalik Buterin
- The main idea: Why not run programs on
the blockchain too? Running applications on
the blockchain could lead to attaching real
world assets, such as stock or property to
the blockchain
- Native cryptocurrency: Ether
What is Ethereum?
Ethereum Concepts
Vitalik Buterin, Founder of Ethereum
22. - Types of nodes:
- Full node : maintains entire copy of BC
- Light node : only makes transactions, stores
block headers only
- Archive node : stores the entire BC along with
and builds an archive of historical data
Ethereum Nodes
Ethereum Concepts
23. - IBM
Smart contracts are simply programs stored on a
blockchain that run when predetermined
conditions are met. They are typically used to
automate an agreement's execution so that all
participants can be immediately sure of the
outcome without any intermediary's involvement
or time loss.
24. - “Program that runs on the
Ethereum blockchain”
- Ethereum allows us to write smart
contracts using a scripting language
called Solidity
- Solidity is “turing complete”
- Wait… but what if my smart contract
is an infinite loop? Can I cease all
nodes on the network?
Smart-contracts
Ethereum Concepts
26. - The EVM is a sandboxed platform
that runs smart contract code
- EVM sees the entire blockchain as a
state, and the EVM itself, as a
state-machine, which takes the
“current state” to another valid “state”
- It is a sandboxed environment, and
runs bytecode. Makes sure smart
contracts cannot do any harm to
nodes
The Ethereum Virtual Machine
Ethereum Concepts
27. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
Fill fuel
28. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
refuel
29. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
refuel
30. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
destination
31. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
EVM
GAS
Operation 1 Operation 2 Operation 3
32. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
EVM
Operation 1 Operation 2 Operation 3
NOM
NOM
33. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
EVM
Operation 1 Operation 2 Operation 3
NOM
NOM
34. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
EVM
Operation 1 Operation 2 Operation 3
Im
Done!
35. - The total amount of computation
used to process a transaction is
measured in a special unit called gas
- But how exactly is the “amount of
computation” measured?
Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
36. - A transaction need to perform a bunch of
smaller computations
- For example, computing 10 + 20 * 30 requires
you to perform a multiplication and an addition
- Each of these smaller computations have well
defined gas price (in the ethereum white paper)
- For each of these operations, gas is consumed.
The function could run to completion, or run out
of gas and abort its execution. Why is this even a
thing tho?
Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
37. - Everytime you make a transaction, you send the
following information with it
- The gas limit: The maximum amount of gas
you are willing to spend for this transaction
- The gas price: The amount you are willing to
pay for 1 gas, in a unit called gwei (1 gwei =
10^-9 ether)
- Tx price = gas limit x gas price
Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
38. Gas Fee, Gas Price, and the Gas Limit
Ethereum Concepts
Higher gas price,
lower waiting
time
Lower gas price,
Higher waiting
time Lower gas limit,
less computations
in your transaction
Higher gas limit,
more computations in
your transaction
Gas price
Tx waiting time Computations
Gas limit
39. Intro to Remix IDE
Ethereum Concepts
Let’s look at an environment which will be our playground to learn solidity!
Live demo time!~ :^)
40. Smart contract compilation process: solc compiler
Ethereum Concepts
.sol file (solidity source)
Solidity compiler (solc)
ABI EVM bytecode
(deployed on the blockchain)
(used by applications to interact with our
smart contract)
42. Data types and variables
What is a variable?
Variables are just the names of
the memory location !!
43. Data types and variables
1. Boolean - true✅ / false❌
2. Integer - Your usual numbers
but without a decimal part
ex: 12, 345,...
Integer
Unsigned
integer
Signed
Integer
● uint8
● uint16,
…
● uint256
● int8
● int16,
…
● int256
but why do we need
different types of
integers based on
their size?
44. 3. Address - Address hold a 20-byte value which represents the
size of an Ethereum address.:
0xb794f5ea0ba39494ce839613fffba74279579268
Data types and variables
This is what an
Ethereum address
looks like
45. Bytes and Strings
Not this Bytes xD
● Bytes are used to store a fixed-sized
character set
● The string is used to store the
character set equal to or more than a
byte and it has dynamic length
46. Enums
The Enums restrict a variable to have one of only a few
predefined values. The values in this enumerated list are called
enums.
47. How do functions break up?
They stop calling each other xD
Functions
General Syntax of a function
A function is a block of organized code
that is used to perform a single task.
LET ME TELL YOU MORE
ABOUT FUNCTIONS…
51. State variables
- State variables are variables that store data on the blockchain
- They persist their value between successive interactions with the smart
contract
- They are declared within a contract block, but outside any function
Let’s have a look
53. Local variables
- In contrast to state variables, local variables are only used within a function
- They only store data they hold till the function executes
- After the function finishes execution, they are deallocated from the EVM’s
stack
Let’s have a look
55. Global variables
- Global variables are special little things
- They are set up by the EVM for us, and store information about the
blockchain, the transaction, and the account that triggered the transaction
- Although there are a lot of them (refer to solidity docs), we look at the
following important ones
- msg.sender: address of the sender
- msg.value: amount of wei sent in the transaction (uint)
- block.timestamp: the current unix timestamp (a uint)
- block.number: the current block number (a uint)
57. Constructor
Chaliye Constructor
shuru karte hain
Nobody:
Literally Nobody:
Le nodes after deploying a contract:
● Constructor is a special function
declared using constructor keyword.
● It is an optional funtion and is used to
initialize state variables of a contract.
● It runs only once when the smart contract
is deployed to the blockchain network.
61. Public
Access Specifiers
The methods and variables can be accessed outside the
smart contract.
Main public hoon , mereko sab
access kar sakte hain
62. Private
Access Specifiers
The methods and variables can be
accessed only within the smart
contract.
Le other smart contracts :
Variables aur
methods kaha hai ???
*Proceeds to add a private access specifier to a variable*
63. QUIZ - 1 !
Chalo, kuch maza
karthe hain…
slido.com
#295704
64.
65. Sometimes it’s a convenience to think about a group of data as a single entity
Grouping data together
Structs
67. - Mapping is very similar to dictionaries in other programming languages.
- It allows for efficient lookup
Imagine looking up the definition of a word in a dictionary.
word → definition
Solidity’s dictionary
Mapping
69. They seem similar, no?
Mapping vs Arrays
- But array index is always a non negative number! On the other hand, Mapings
“index” can any datatype!
- The main advantage of arrays are that they are iterable. Mappings are not
iterable.
- Mapping can grow as big as they want, and still remain very efficient! Array’s
on the other hand, are not as efficient when they are of huge size.
- Mapping can be used only to store things in storage, Solidity does not
support in-memory mapping.
70. Returning results from a function
Revisit: Functions
- To mention what datatype a function will return, we use the returns keyword
- To return a value from a function, we use the return keyword
Let’s play around in remix.
71. Pure and View Functions
Revisit: Functions
- Pure functions: These functions promise the EVM that they will not read or
update any state variables or global variable
- View functions:These functions promise the EVM that they will not update
any state variable
Let’s look at it in remix again!
Pure and View functions do not consume any gas when invoked externally.
However they do cost gas when called from another function.
72. Storage, memory and calldata
storage: The location type where the state variables are stored on blockchain
which means types that has storage location are persistent
memory: Variables are in memory and they exists during the function call
which means variables that got this location are temporary and after
function execution finished, they won’t exist.
calldata: Non-modifiable, non-persistent data location where function
arguments are stored, behaves mostly like memory data location
73. Assignment behaviour
- Assignments between storage and memory (or from calldata) always create
an independent copy.
- Assignments from memory to memory only create references. As a result
changes to one memory variable are also visible in all other memory variables
that refer to the same data.
- Assignments from storage to a local storage variable also only assign a
reference.
- All other assignments to storage always creates independent copies.
74. Ways to send ether
Payable
- The payable keyword adds functionality to send and receive ether.
- If you want a function to be able to receive ether, then tag it with the payable
keyword
- An address datatype can also be made payable, in case you want to transfer
ether to the address stored in it.
- You can send ether to a payable address in three ways. transfer(), send() and
call{value: …}()
75. Create a CRUD application on a
list of users.
● C - Create
● R - Read
● U - Update
● D - Delete
Let’s write a simple CRUD Smart Contract
Chalo
Code karte hain
76. However, some gas fee will be spent for this
right?
What if my transaction
fails or if it was an
invalid transaction?
77. Possible invalid transactions:
1. Invalid access
2. Access something that doesn’t
exist
3. Absence of something that’s a
mandatory field
4. Insufficient amount for transfer
There is no point of spending gas
fee for an invalid transaction!
78. Abort execution and revert state changes providing an
explanatory string
revert(failure_message)
79. Abort execution and revert state changes if condition is
false and provide error message.
require(condition, failure_message)
80. Modifiers are used for automatically checking a condition,
prior to executing a function.
● Reduce code redundancy
● Re-use same modifier in multiple functions
modifier
83. Develop a smart contract where users create
posts (sastha tweets) and other users who
like it can tip some ethers.
Project: Sastha Twitter
84. 1. Write Smart Contract.
2. Setup local blockchain.
3. Create Frontend website.
4. Connect frontend & blockchain.
5. Interact with the Blockchain
from the website.
Let’s cook something now…
85. MetaMask provides the
simplest yet most secure
way to connect to
blockchain-based
applications. You are
always in control when
interacting on the new
decentralized web.
Metamask
Tools
86. Node.js is a JavaScript runtime
environment that helps to run JS
outside that browser.
Node.js
Tools
87. A world class development
environment, testing
framework and asset pipeline
for blockchains using the
Ethereum Virtual Machine
(EVM), aiming to make life as
a developer easier.
Truffle.js
Tools
npm install -g truffle
88. Ganache setups up a local
blockchain network in our PC
with just one click that helps
us to test & deploy smart
contracts.
Ganache
Tools
89. Let’s deploy our smart contract to local blockchain.
Deploy Smart Contract
1. Make sure SasthaTwitter.sol
code is present in
/contracts directory.
2. Add this contract to
/migrations directory.
truffle migrate
Head over to
bit.ly/bc-sastha-tweet
90. Connect frontend website to our smart contract.
1. cd app/
2. npm install
3. npm run dev
Frontend Website
Connect Metamask to Ganache:
1. Open Metamask
2. Click on Add Networks in Settings
3. New RPC URL: http://localhost:7545
4. Chain Id: 1337
91. Make our website interactive with the smart contract.
Decentralized Application
1.Create Posts - uncomment lines a to b
In app.js:
2.Get all posts - uncomment lines f to g
3.Tip post - uncomment lines p to r
92. Play around in the website…
- Create some posts
- Tip some ethers to other posts
93. That’s cool. Now you all know how to
write smart contracts and connect it
with frontend!
94. Feel free to ask any doubts/queries or any
questions from today’s workshop.
Don’t feel shy… We are all same😅
QnA
Any queries???
96. It is also necessary to create a
user friendly website such that
It allows users to interact with
your smart contract!
What next?
Most importantly,
Frontend + Smart Contract
= FullStack Developer 😉
Web
Development
Blockchain
Development
Me
97. Connect With Us!
Scan this QR code to access all
our social media handles and
links!
links.dscjssstu.in
98. We want to hear from you!
We would highly appreciate your honest feedback.
Only the people who’ve filled this form and attended the
entire workshop will receive the digital certificates.
Certificates will be rolled out within a week.
bit.ly/gdsc-breakchain-feedback