In this presentation, we take an unusual approach to introducing Ethereum - we use a blockchain explorer to understand how the ethereum works and explore the underlying concepts such as blocks, transactions, nonce, mining, etc
4. What did we observe?
❖ “Ethereum” is a blockchain
❖ “Ether” is the currency (crypto-currency) - ETH
❖ There are “blocks” and “transactions”
❖ The latest block added was 5916712
❖ There are 265.09 M transactions so far
6. What did we observe?
❖ Current market cap is USD 47 billions
❖ Awesome for something in 3 years (initial release was in 30 July
2015)
❖ The last block was added 14.5 seconds back
❖ That’s typical of the rate in which blocks are added
❖ The transactions per second is 5.2
❖ That’s pathetic in financial industry terms in which a millions
transactions per second is not a big deal
❖ We’ll discuss “Hash Rate” and “Network Difficulty” a bit later
8. What did we observe?
❖ Every block is sequentially numbered
❖ Starting from zero, which is a special “genesis block”
❖ Each block has many transactions
❖ Not fixed number with wide variations - e.g., one was 19 and
another one was 104
❖ There are different “miners” - like “Ethermine” and “f2pool_2”
here
❖ And they are rewarded with Ethers (typically around 4 ethers)
9. Let’s zoom in for more details
https://etherscan.io/blocks
The Nth
block
How old is
the block?
How many transactions
are in this block?
How many “uncles”
for this block?
Who was that lucky
miner to get the ethers?
How many Ethers
was the reward to
the miner?
How much gas
was consumed?
What was the
maximum gas
allowed?
How much was the
average gas price per
transaction?
10. Let’s look at an actual block
How many
transactions are
there in this
block?
What is the hash
value of this
block? (256 bits)
Pointer (hash) to
the previous
block
What is the
name and
address of the
successful
miner?
The size of the
block in bytes
Proof-of-work
value
How many
ethers were
rewarded to the
successful
miner?
11. Let’s look a few actual transactions
Hashes of the
transactions in
this block
All these transactions
belong to the same block
(mined at the same time)
Addresses of the
transaction initiators
This is a Ether currency
transaction (to this
recipient address)
These three are
transactions to
contract addresses
Every transaction
(transferring ether or to
contract and even failed
ones) costs money (its all
money, honey!)
This is a failed
transaction (Log says:
“Error encountered
during contract
execution [Out of gas])”
12. Let’s look at an actual transaction
The hash code of
the transaction
(256 bites)
The transaction
is part of this
block
When did this
transaction
happen?
The source
address that
initiated this
currency transfer
transaction
How much Ether
was transferred
to the recipient?
What was the
gas limit and
how much was
consumed?
The money was
sent to this address
What much did the
sender have to shell
out to make this
transfer?
19. It’s all public info!
❖ With just the address, anyone can view the balance,
number of transactions, to which account the ether came
in or went out, etc.
❖ But only if you own the account, you can perform the
transactions ;-)
❖ Transactions could be to other accounts or to contracts
❖ There could be “token transfers” as well - we’ll discuss
tokens later
22. “Hash” - fingerprint of data
"Priyanka Chopra (Piggy Chops)"
'ee457b98565f0c6f6b013acab80ea02dfa80e7e8'
SHA1
23. Using SHA-1 in Python
>>> import hashlib
>>> text = b"Priyanka Chopra (Piggy Chops)"
>>> hashlib.sha1(text).hexdigest()
'ee457b98565f0c6f6b013acab80ea02dfa80e7e8'
>>> text = b"Deepika Padukone (Deepi)"
>>> hashlib.sha1(text).hexdigest()
‘4efdf9172c4d3fa56540466f8c8a371a45e472fc’
>>> len('4efdf9172c4d3fa56540466f8c8a371a45e472fc')
40
>>> len('4efdf9172c4d3fa56540466f8c8a371a45e472fc') * 4
160
24. Using SHA-3 in Python
>>> import hashlib
>>> text = b"Deepika Padukone (Deepi)"
>>> hashlib.sha3_256(text).hexdigest()
'6229691c1f27cb6b9d4bce8b87ca1a3f0521cdc4aaff1b572be5c400946af29d'
>>> len(_)
64
>>> _ * 4
256
‘Ethereum's development coincided with the development of the SHA3
standard, and the standards process made a late change in the padding of
the finalized hash algorithm, so that Ethereum's "sha3_256" and "sha3_512"
hashes are not standard sha3 hashes, but a variant often referred to as
"Keccak-256" and "Keccak-512" in other contexts.’
- From https://github.com/ethereum/wiki/wiki/Ethash
25. For given text, hex is same!
>>> import hashlib
>>> text = b"Priyanka Chopra (Piggy Chops)"
>>> hashlib.sha1(text).hexdigest()
‘ee457b98565f0c6f6b013acab80ea02dfa80e7e8'
>>> anothertext = b"Priyanka Chopra (Piggy Chops)"
>>> hashlib.sha1(anothertext).hexdigest()
‘ee457b98565f0c6f6b013acab80ea02dfa80e7e8'
>>> variationtext = b"Priyanka Chopra"
>>> hashlib.sha1(variationtext).hexdigest()
‘0a6b5f3111ba3bcc87445942ec2bfcbe2dc28644'
http://www.sha1-online.com/
28. Programmatic account creation
$ cat createacct.js
const ethers = require('ethers');
var wallet = ethers.Wallet.createRandom();
// var privateKey = "0x0123456789012345678901234567890123456789012345678901234567890123";
// var wallet = new ethers.Wallet(random);
console.log(wallet);
$ node createacct.js
Wallet {
privateKey:
'0xf10107a2dd4e0901374d93324a59ade40512d7c946746cdd9b24dc75ceba81a1',
provider: [Getter/Setter],
defaultGasLimit: [Getter/Setter],
address: '0xCbd98A04812e824fC481e6244A3D776c0cA8Ef4f',
sign: [Function],
mnemonic:
'field crop small food shoe design chronic push fox lazy keep clinic',
path: 'm/44'/60'/0'/0/0' }
$
29. Programmatic ether transfer
tiny.cc/ethtransfer
// we are using .env file for configuration details (i.e., from & to account addresses & the
private key for the from address)
require('dotenv').config()
// we are only using the 'ethers' module for transferring ether programmatically
const ethers = require('ethers');
const providers = ethers.providers;
// we are currenly using rinkeby test network; change it to mainnet for real transactions (and
improve this code before you do that ;-))
const network = 'rinkeby';
const provider = providers.getDefaultProvider(network);
var address = process.env.FROM_ADDRESS
console.log(`Using the given from and to addresses & the private key for the from address for $
{network} network`);
// first retrive the account balance (you cannot transfer if you have no ether or less ether than
the transfer amount!)
const balance = provider.getBalance(address).then(function(balance) {
var etherString = ethers.utils.formatEther(balance);
console.log(`The balance in your account is: ${etherString}`);
return etherString;
});
30. Programmatic ether transfer
tiny.cc/ethtransfer
const privateKey = process.env.PRIVATE_KEY
const wallet = new ethers.Wallet(privateKey);
wallet.provider = provider;
// how much ether to transfer
const amountToTransfer = "0.01";
// create a transaction object with the to address and the amount of ether to be transferred
var transaction = {
to: process.env.TO_ADDRESS,
value: ethers.utils.parseEther(amountToTransfer)
};
// get the current estimate for the amount of Gas required for performing the transaction and set that as the gas limit as well
const estimateGasPromise = wallet.estimateGas(transaction);
estimateGasPromise.then(function(gasEstimate) {
console.log(`The estimated gast for performing the transaction is: ${gasEstimate.toString()}`);
console.log(`Keeping the gas limit also the same: ${gasEstimate.toString()}`);
transaction.gasLimit = gasEstimate;
// that's it! do the transaction
var sendTransactionPromise = wallet.sendTransaction(transaction);
// if the transaction succeeds, you'll get here with the transaction hash!
sendTransactionPromise.then(function(transactionHash) {
console.log(`Transaction successful!!! `);
console.log(`The transaction hash is: ${transactionHash.hash}`);
// go to this URL to check more details about the transaction
console.log(`Etherscan transaction URL for complete details: https://${network}.etherscan.io/tx/${transactionHash.hash}`);
});
});
// done!
31. Programmatic ether transfer
tiny.cc/ethtransfer
$ node working.js
Using the given from and to addresses & the private key for the from address
for rinkeby network
The balance in your account is: 2.979958
The estimated gast for performing the transaction is: 21000
Keeping the gas limit also the same: 21000
Transaction successful!!!
The transaction hash is:
0xd08f20663a1c957490ca1e3e748db7bf1e0e65959c58ad7d608bae93a75c47fd
Etherscan transaction URL for complete details: https://rinkeby.etherscan.io/
tx/0xd08f20663a1c957490ca1e3e748db7bf1e0e65959c58ad7d608bae93a75c47fd