Account address is like email address.
One account can be used across different networks
The public key is when pasted in browser console gives base10 of the number
For Private key put 0x (= hexadecimal no.) before the number (else syntax error)
Every Ethereum account is completely decoupled with any eth network (sepolia/goerli)
On any test network you can request test Eth.
Sepolia faucet registration form : [Link]
When the pub key is submitted we get some test tokens with the below diagram:
NOTE : step3 is a backend node js server which uses the web3js library to create the transaction
object.
Web3js lib used by devs to interact with any ethereum network (every node below is a computer in
the network)
TRANSACTION OBJECT:
Nonce : random number ; mainly used to prevent replay attack
V,R,S : numbers which can be generated from pvt key of sender but pvt key cannot be generated
from these 3 numbers. V/R/S proves legitimacy of the transaction.
Why the transaction takes times?
When transaction was sent to n/w it was sent to a particular node. This node communicates with
rest of the n/w
When our transaction reaches the node there can be other transactions reaching the same node at
the same time. The node groups these trxs in a block and runs a validation logic (mining) on the
block. This mining takes some time.
MINING
[Link]
SHA256 hash is like a digital fingerprint. It changes based on the data that’s present
[Link]
Each block is a demoed in the link. A block is signed only when the hash starts with 4 zeroes.
We click on mining and the nonce changes to reset the hash to a value till its signed.
[Link]
Blockchain consists of series of blocks which consist the hash from the previous one. If one of
the block is changed then all the succeeding blocks’ hash changes and the block breaks.
Everytime we will have to re-mine each block upon alteration and all the blocks succeeding
it. This is how blockchain resists change.
[Link]
How to know if a blockchain was remined?
Peers in internet have a complete copy of the blockchain. Lets alter a block on Peer B and re-mine
the block. We will notice the hash of peer B is different than the hash of all the other Peers and going
by democracy what other peers reflect will be correct data.
Last block was re-mined but the hash value is different from Peer A and C whose values match.
Tokens
[Link]
In the data part we capture transfer money, again if value is changed then the chain breaks.
Coinbase TX
[Link]
Previously we only tracked money transfer but here we are tracking the money from its origin.
Ethereum Blockchain
The Algo is looking for a hash less than some target value.
The hashes are 64 bit in length below are the min and max values possible for the for the same
Time taken to hash everything from 0 to the target nonce value is called Block time.
The (proof of work) Algo will have to run multiple times going through multiple hashes to arrive at
the correct number, less than the specific number.
Block time also includes the time required to distribute the solution to all nodes in the n/w once the
one node finds the solution.
The target value against which the algo calculates the hash keeps changing overtime because
- The target avg block time in etherium is 15 secs, if the block time is more than this the algo
adjusts the target to set it to a higher number (with a higher number its faster to find a target
hash/nonce)
- The node in the n/w is always in flux, a node can join anytime and can leave anytime. At
certain point the nodes in n/w could be the highest/lowest. The target is adjusted
accordingly
[Link]
Account we created with metamask is an external account and lives in a completely different
domain and completely decoupled from any n/w. Same ext account can connect to
Main/Rinkeby/sepolia n/w but a contract are specific to individual n/w
From each individual’s node in the network some smart contract source code will be deployed
and in the n/w it will be present as in instance as an instance to the n/w (similar to java class and
its instances). The source code from system can be deployed multiple times in a n/w or to
multiple networks.
Bytecode is deployed to the network & ABIs interact with the smart contract.
As devs want to interact with a smart contract we will be doing so by interfacing with the ABI.
IDE for smart contracts : [Link]
Sample contract which goes inside the [Link] file
When a public class variable is present then solidity creates a getter for that by itself i.e the
getMessage function above is superfluous. In remix the “message” already appears with the
same functionality.
The remix IDE provides free ether coins to be able to do transactions.
Initially when metamask transaction was authored from external wallet the transaction will try to
create a new contract to specific n/w. The n/w will attempt to create the contract.
Creation of contract is similar to money transfer except few changes as below:
Nonce is the sender account visible also in remix IDE from where the transaction is done.
Two kinds of tractions can happen where contract is being created and another one is actual
payment transaction. If first kind then to field will be empty (to field blank = new contract)
Data field will contain code visible to the world in bytecode so no proprietary code should be
part of the data field.
Value -> with new contract also some initial balance of ether to play around with the contract
creation process.
Call to any setter kind of function a transaction. Every transaction costs something (ethers will be
deducted) and returns a hash value as part of the transaction. A transaction is something which
alters the value in the blockchain.
Sample below calling the set message:
Sample call on message (class variable acts as getter by default)
Hovering over the functions also shows the same
Every operation (mathematical or variable storage) costs something in transaction value. The
contract developer would need to mention the what is the price or gas limit that will be allowed
on a transaction and the price of gas per unit.
After add and subtract the below operation stops as the gas limit is exceeded multiply is carried
out
If setMessage is called then in console green check is visible which means its costing gas/money
but when only message is called no green check.
Address datatype
Address is 20 bytes and has a field called balance.
Function getAddressBalance() public view returns (unit) <= will return balance of type unsigned
int type in wei (1eth = 10^18 wei)
Message Datatype
Message is available in public scope throughout a contract. Need not be declared.
[Link] will contain the address of the account interacting with the contract (Account ->
Contract). If contract is interacting with another contract then it contains the address of the
contract which interacted with it (Account -> Contract -> Contract) Running [Link] on
Contract will give address of Contract
View and Pure type functions
View functions are only getter functions they can return class variable.
Pure functions can only call variables that not class variables or other pure functions.
A setter shouldn’t return anything unless used for inter contract calls (Contract -> Contract)
In below example setter returns something.
Constructor is called only once during deployment
Write contract where message can be updated only by the owner but can be read by everyone
Metamask banckend infra is currently alchemy (proabably runs on AWS)
Metamask uses the 12 word mnemonic as seed phrase used to create the key pairs. The public
key from the same is used in its Ethereum account.
ECRECOVER Algo takes the r,s,v values from a Tx and can recreate the Ethereum account.
To field empty but data field populated = Contract deployment
[Link]
[Link]
transactions/
Payable
A smart contract can receive eth if its function is of type payable. Amount sent can be got from
field [Link]. Below we are sending back the money to sender address back if 1 eth amount is
not matching (NOTE : Sender address has to be of type ‘payable’ that’s why typecasting :
payable([Link]))