Dapeng Li
May 2021
- Bitcoin (transaction)
- Ethereum (basic programming)
- blockchain
A peer-to-peer electronic cash system.
https://www.youtube.com/watch?v=g6iDZspbRMg
https://en.wikipedia.org/wiki/Bitcoin
- balance (who owns how much)
- payment (who paid whom)
public/private keys
bearer payment, no identity
keep private key as secret (!)
https://en.bitcoinwiki.org/wiki/Private_key
from, to, amount
https://www.blockchain.com/btc/tx/671a30fd9553399b21d4c6ceaee9c4dbaa980f567cd6abd4c206e57c6f28dd3a
signed by the sender
block contains transactions
block references parent
https://www.blockchain.com/btc/block/0000000000000000000999b09f3d68de48b87e0412cbc6e4dd8fd00fe7ecabf1?page=3
What if Bob replays the transaction?
No state of "balance" on the blockchain
Unspent Transaction Output (UTXO)
https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch06.asciidoc#transaction-outputs-and-inputs
Add up all UTXOs
Where does Bitcoin come from?
new block mints new Bitcoin
new block roughly every 10 minutes
"miner" receives rewards
Who can create block?
Puzzle (Proof of Work)
difficult to solve, easy to verify
decentralized system needs consensus
https://github.com/ethereumbook/ethereumbook/blob/develop/04keys-addresses.asciidoc#cryptographic-hash-functions
deterministic
one-way
collision resistant
https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch10.asciidoc#proof-of-work-algorithm
hash(blockheader) <= target
Other miners validate block
Start the next round after validation
https://github.com/bitcoinbook/bitcoinbook
inefficient
scale?
similar to Bitcoin
difference
high level languages compiles to bytecode
bytecode runs on Ethereum Virtual Machine
Object-Oriented
https://github.com/ethereumbook/ethereumbook/blob/develop/07smart-contracts-solidity.asciidoc#introduction-to-ethereum-high-level-languages
pragma solidity >=0.4.22 <0.6.0;
contract Ballot {
// structs
struct Voter {
bool voted;
address delegate;
uint vote;
}
struct Proposal {
bytes32 name;
uint voteCount;
}
// variables
address public chairperson;
mapping(address => Voter) public voters;
Proposal[] public proposals;
constructor(bytes32[] memory proposalNames) public {}
// methods
function giveRightToVote(address voter) public {}
function vote(uint proposal) public {}
function winningProposal() public view
returns (uint winningProposal_) {}
}
https://docs.soliditylang.org/en/v0.5.3/solidity-by-example.html#voting
Turing complete
halting problem - can it stop?
Pay to use
https://github.com/ethereumbook/ethereumbook/blob/develop/06transactions.asciidoc#transaction-gas
Smart contract
Oracle: "bridge" between smart contract and off-chain
https://github.com/ethereumbook/ethereumbook/blob/develop/11oracles.asciidoc
pragma solidity ^0.4.1;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract EthUsdPriceTicker is usingOraclize {
uint public ethUsd;
function EthUsdPriceTicker() payable {
queryTicker();
}
function __callback(bytes32 _queryId, string _result, bytes _proof) public {
if (msg.sender != oraclize_cbAddress()) throw;
ethUsd = parseInt(_result, 2);
queryTicker();
}
function queryTicker() external payable {
oraclize_query(60 * 10, "URL",
"json(https://min-api.cryptocompare.com/data/price?\
fsym=ETH&tsyms=USD,EUR,GBP).USD");
}
}
https://github.com/ethereumbook/ethereumbook/blob/develop/11oracles.asciidoc#oracle-client-interfaces-in-solidity
Dapp (Decentralized app)
smart contracts with web interfaces
https://www.manning.com/books/blockchain-in-action
https://github.com/ethereumbook/ethereumbook/blob/develop/12dapps.asciidoc
ERC-20: fungible (interchangeable) tokens
contract ERC20 {
function totalSupply() constant returns (uint theTotalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns
(bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns
(uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
https://github.com/ethereumbook/ethereumbook/blob/develop/10tokens.asciidoc#the-erc20-token-standard
ERC-721: non-fungible tokens (NFT)
interface ERC721 /* is ERC165 */ {
event Transfer(address indexed _from, address indexed _to, uint256 _deedId);
event Approval(address indexed _owner, address indexed _approved,
uint256 _deedId);
event ApprovalForAll(address indexed _owner, address indexed _operator,
bool _approved);
function balanceOf(address _owner) external view returns (uint256 _balance);
function ownerOf(uint256 _deedId) external view returns (address _owner);
function transfer(address _to, uint256 _deedId) external payable;
function transferFrom(address _from, address _to, uint256 _deedId)
external payable;
function approve(address _approved, uint256 _deedId) external payable;
function setApprovalForAll(address _operator, boolean _approved) payable;
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
mapping (uint256 => address) private deedOwner;
https://github.com/ethereumbook/ethereumbook/blob/develop/10tokens.asciidoc#erc721-non-fungible-token-deed-standard
PoW (proof of work)
PoS (proof of stake)
https://github.com/ethereumbook/ethereumbook/blob/develop/14consensus.asciidoc#consensus
https://github.com/ethereumbook/ethereumbook/blob/develop/01what-is.asciidoc#components-of-a-blockchain
multiple disciplines
https://github.com/ethereumbook/ethereumbook/blob/develop/01what-is.asciidoc#why-learn-ethereum
https://www.manning.com/books/blockchain-in-action
https://deepmind.com/blog/article/trust-confidence-verifiable-data-audit
https://www.manning.com/books/blockchain-in-action
Divided opinions
Technology is not endorsement for everything.
DYOR, good luck.
https://www.manning.com/books/blockchain-in-action