Blockchain , Deploying your first smart contract to azure ethereum blockchain.
Slides from my session in "Global Azure Bootcamp Chandigarh"
Presentation starts with basic terms like transactions , ledger and contracts. Talks about what is blockchain and ethereum and concludes with deployment of a smart contract to azure ethereum blockchain.
4. Contracts
“I trust the broker [ 3rd party ] so I’m
willing to make the deal happen at 3%
brokerage”
5. Decentralization
Imagine buying a sunglasses
20 years back . . . .
Only 1 shop in the area [
centralized ]
High price
Hard to trust the quality as
there’s no way to measure
Today . . . .
Multiple websites / apps with all
time access [ decentralized ]
Competitive price with
comparison
Trust relatively high because of
huge competition / reputation
issue
7. Contents
Phase-1
1. Transactions
2. Ledger
3. Contracts
4. Decentralization
Phase-2
1. What is blockchain?
2. What is Ethereum?
3. Smart Contracts
4. EVM
5. Remix IDE
6. Solidity
Phase-3
1. Create Resource
2. Setup Ethereum
Consortium
Blockchain
3. Deploy network
4. Deploy smart
contract
8. #1
genesis
#2 #3 #4
What is Blockchain?
“A digitally distributed ledger which stores cryptographically linked blocks of data [ transactions ] in a
way which makes the data immutable , final and tamper-proof”
9. Block“
A digitally distributed ledger stores
transactions in a structure called blocks
of data or transactions” ,
“a block is a container / storage-unit for
storing transactions , it also contains
metadata like block-number, timestamp,
txns, nonce, hash etc”
#1110
Number: #1110
Data: {
“1110 -> 4343”: “$23”,
“2212-> 3232”: “#0010101010”
}
Timestamp
Prev hash
nonce
10. Hash
“A hash is a cryptographic function with
3 properties”
1. Uniqueness
2. Fixed Length
3. Irreversible
Welcome to Blockchain demo!
0xa078c6a041f57bbb8d369132164f58fb54c67fddc3179d4a5887bec48a0722b3
11. #1
Data: { . . . }
Time: xyz
Nonce: 1235
Prev_hash: 0x0000
Hash: 0x223a
#2
Data: { . . . }
Time: mno
Nonce: 4674
Prev_hash: 0x223a
Hash: 0x9ad3
“Hash of previous block is considered as one of the input parameters when calculating the
hash of current block making a chain of cryptographically linked blocks”
13. Miners and
Mining
Mining is the process of calculating a
valid hash for a given block which
satisfies all the preconditions
14. Mining =
Calculating the
Valid hash
Nonce is constantly updated to reach a
value where the hash signature become
valid to reflect the POW
#1, data = { . . . }, timestamp = xxx, nonce=1
Hash = 0xa453. . . . .
iteration-1
#1, data = { . . . }, timestamp = xxx, nonce=1
Hash = 0xa453. . . . .
#1, data = { . . . }, timestamp = xxx, nonce=1
Hash = 0xa453. . . . .
#1, data = { . . . }, timestamp = xxx, nonce=n
Hash = 0x0000ab89. . . . .
iteration-2
iteration-3
iteration-n
15. Chain
A chain of blocks is cryptographically
connected in such a way that tampering
with one of the blocks invalidates all the
blocks ahead of that block.
What is this
blocks is
tampered
with ?
17. Ethereum
Ethereum is a distributed peer to peer
network which consists of a distributed
ledger and blockchain capable of
running smart contracts.
18. Smart Contracts
“Digital contracts deployed on
blockchain network with the ability to
enforce terms of a contract”
A B
address A;
address B;
Contract HouseRent {
. . . . .
. . .
if ( timeToPayRent ) {
pay(A,B,45);
}
}
19. Why Ethereum ?
1. Ethereum network is created for
DAPPS
2. Developer tools
3. Ease of Learning
4. Support
Can I write smart
contracts on top of
Bitcoin blockchain
as well ?
20. EVM
Ethereum Virtual Machine is designed
around the ethereum client
specification. This is where all the
Ethereum bytecode runs.
Ethereum Bytecode
Ethereum Virtual Machine
Executed by
EVM execution involves iterating over some
bytecode, executing each opcode until execution is
complete
21. Opcodes
How codes execute on EVM?
The Ethereum yellow paper
defines approximately 130
opcodes.
Examples >>
● ADD: 0x01 { Addition operation }
● PUSH32: 0x7f { Place 32-byte (full word) item
on stack }
● CREATE: 0xf0 { 0xf0 CREATE Create a new
account with associated code }
22. Cost of
Computing
To run code on ethereum
blockchain , you’ve to pay for
each instruction that executes
Examples >>
● ADD: 0x01; 3 GAS
● PUSH32: 0x7f; 3 GAS
● CREATE: 0xf0; 32000 GAS
23. Gas Price
To run code on ethereum
blockchain , you’ve to pay for
each instruction that executes
During normal times:
● 40 GWEI Gas Price will almost always get you into the next
block.
● 20 GWEI will usually get you within the next few blocks.
● 2 GWEI will usually get you within the next few minutes.
The total cost of a transaction (the "TX fee") is the
Gas Limit * Gas Price.
24. Solidity
The programming language for DAPPS
Solidity is a high level language which
compiles to ethereum bytecode
Ethereum Bytecode
Ethereum Virtual Machine
Solidity code
44. Funding your
account
Metamask is a chrome extension which
allows to interact with blockchain
without downloading all of the data of
the blockchain.
Metamask is a thin client.
45. Sending ether
from your own
blockchain
You rule your world , you create ethers
and you own them here.