Blockchain Workshop
By: Swapnil Kole
Blockchain is a distributed ledger based technology which uses consensus based decisions to achieve trust in a peer-2-peer network among unknown peers.
What is Blockchain from Tech side?
Original Idea
Digital Timestamp => No backdate & no tampering
Timestamp => https://www.epochconverter.com/�
Hash
Number Systems => Binary(110), Octal(05), Decimal(9), Hexadecimal(0x4F)�Conversion
Hash => Unique hex no. to represent address
Function => i/p -> process -> o/p
Hashing Func => i/p = any type & o/p = a uniform length of hash
Contents of a Block
Timestamp
Nonce
Chain of Blocks
Checkpoint - 1
Underlying Technologies of Blockchain
Peer-2-peer network
Blockchain Protocol
Cryptography
Peer-2-peer network
Cryptography
Asymmetric Key Encryption : Generates keys & if public key encrypts then private key can decrypt vv.
Private key Public key
Piyush
Private key Public key
Roshni
Hashing : A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values.
Properties : One-way function, Avalanche effect, No dublicacy.
Best hashing functions : SHA-256 and Keccak
Blockchain Protocol
Checkpoint - 2
ADVANTAGES OF BLOCKCHAIN
Decentralized Control�
Security
Transparency and Integrity
Immutable storage
Blockchain has immutable storage, once data goes into the block nobody can change it because changing the data will change the hash of the block. This also makes it unhackable.
STRUCTURE OF A BLOCK
Difficulty
MERKLE TREE
O(logn)
*Tree Data Structure
Checkpoint - 3
HOW BLOCKCHAIN WORKS
MINING PROCESS
Hashing rate for the target block coming through the miner’s calculations
The hash of each block starts with leading zeroes.
Nonce: Number only used once. Simple no. combined with the hash of the block to get the starting string with zeroes equal to the difficulty.
Consensus :A consensus mechanism is a fault-tolerant mechanism that is used in computer and blockchain systems to achieve the necessary agreement on a single data value or a single state of the network among distributed processes or multi-agent systems, such as with cryptocurrencies.
Checkpoint - 4
TYPES OF BLOCKCHAIN
BITCOIN
ETHEREUM
SMART CONTRACT
ETHEREUM VIRTUAL MACHINES
DAPPLICATIONS
Checkpoint - 5
Accounts
Externally Owned Accounts
Needs to join ethereum network
EOA are controlled by private keys
Interact with the blockchain using transactions.
Has a ether balance
Smart Contract Accounts
CA controlled by the code and can be activated only by an EOA
Represents a smart contract
Performs operations of arbitrary complexity, manipulate its own persistent storage i.e. can have its own permanent state, can call other contracts.
Has a ether balance
Gas
“Gas” is a special unit in Ethereum which is different from ether.
It measures the amount of “work” a set of action takes to perform.
Gas ⍺ computational resources
Every action needs crypto fuel or gas
Transactions are rejected if fee specified and the gas points are not sufficient.
Leftover gas is transferred back to sender.
Gas limit for each block.
Example: gas limit/block = 15000 & (gas/trans = 300) => 50 trans/block
Ether Denomination Table
Smart Contract in Solidity
Smart contracts provides a layer of computational logic that can be executed on the blockchain, thus availing the features enabled by blockchain framework.
Solidity: Programming language
Checkpoint - 6
Practical Hands-on
Confidential
Customized for Lorem Ipsum LLC
Version 1.0
Metamask
remix.ethereum.org
A crypto wallet & gateway to blockchain apps.
Remix
Remix is a powerful, open source tool that helps you write Solidity contracts straight from browser. Written in Javascript, Remix supports both usage in the browser and locally.
Remix also supports testing, debugging and deploying of smart contracts and much more.
Solidity Language
Compiler stmts => pragma solidity ^0.5.0;
Contract Object => contract myContract{ }
Variables
All variables are initialized by zero, false, ”0x00000…” or ‘’.
Uint8 - uint256 … int8 - int256 - effective gas consumption.
Bool used for either true or false
Strings are non-indexable
Address - Sending funds and account balances. Holds 20 bytes.
Mapping - Associative arrays or key-value pairs.
Struct - User defined data type
Arrays- Many variables of same data type
Enums - User defined data type & limited set of values
Functions
Functions - A block of code that does work. Reusable.
2 Types of functions in solidity
SubTypes of functions
Visibility of functions
Important Properties
Error Handling
Errors revert the state.
Modifiers
Importing of files
Inheritance
Industrial Topics
Understanding the market
Thank you.