Professional Documents
Culture Documents
Ethereum Blockchain
Ethereum Blockchain
Ethereum Blockchain
Data thực tế trên các Blockchain khác thường gồm 1 tập các Hash dùng để định danh cho Block và nội dung (data) của
Transaction. block. Hash là duy nhất, nếu bạn thay đổi nội dung bên trong
block, thì hash sẽ khác
Block đầu tiên trong chain gọi là Genesis Block ASIA BLOCKCHAIN CENTER
P2P & Cơ chế đồng thuận Proof of Work ?
P2P Network là mạng ngang hàng, có nghĩa ai cũng có thể tham gia, sau khi tham gia thành công, sẽ giữ 1 bản copy dữ liệu
blockchain. Chúng được định nghĩa là 1 Node
1 Block mới được tạo bởi 1 node nào đó, thông qua mạng P2P, block sẽ được gửi tất cả node trong mạng. Tất cả node khi nhận block, chúng sẽ xác thực
block hợp lệ hay không. Sau đó thông qua giao thức đồng thuận, chúng sẽ tập hợp kết quả xác thực tất cả các node về block, trên 50% đạt được sự đồng
thuận về block hợp lệ thì block sẽ được đưa vào chuỗi
Consensus protocol
Proof of Work
Proof of Stake
Proof of Burn
Proof of Authority
Raft consensus
Federated consensus
Proof of activity
Proof of elapsed time
Proof of capacity
Proof of Work (PoW)
POW is the most common consensus mechanism and is used in Bitcoin and Ethereum. When a new block of transactions is being added to the
blockchain, to verify these transactions, POW is performed by miners (i.e., powerful computers or processors) that are competing with one another to
solve a cryptographic problem (i.e., hash puzzle). The cryptographic problem is based on the new block of transactions and also all other previous
transactions block in the blockchain. The cryptographic problem is designed such that it is extremely difficult and time consuming to solve it (i.e.,
hashing) but once found by one of the miners, the solution is easily verifiable on the network by all other miners. Once the cryptographic solution has
been verified as valid, the miner who solved it receives a mining reward for the computational work being done to solve the cryptographic problem.
PoW
Features of Proof of Work system:
There are mainly two features that have contributed to the wide popularity of this consensus protocol and they are:
It is hard to find a solution for the mathematical problem
It is easy to verify the correctness of that solution
Main issues with the Proof-of-Work consensus:
The Proof-of-Work consensus mechanism has some issues which are as follows:
The 51% risk: If a controlling entity owns 51% or more than 51% of nodes in the network, the entity can corrupt the blockchain by gaining the majority of the
network.
Time consuming: Miners have to check over many nonce values to find the right solution to the puzzle that must be solved to mine the block, which is a time
consuming process.
Resource consumption: Miners consume high amounts of computing power in order to find the solution to the hard mathematical puzzle. It leads to a waste of
precious resources(money, energy, space, hardware). It is expected that the 0.3% of the world’s electricity will be spent to verify transactions by the end of
2018.
Transaction confirmation takes about 10–60 minutes. So, it is not an instantaneous transaction; because it takes some time to mine the transaction and add it to
the blockchain thus committing the transaction.
PoS
POS is a consensus mechanism designed to mitigate some of the criticisms of POW. The concept is based on the idea that miners that hold a large
amount of cryptocurrency have a larger stake in ensuring the validity of the blockchain.
In POS, a miner has to submit a portion of coins as their stake. The coins being staked have a “Coin Age”, which is basically a measure of how long a
coin holder has held onto coins without spending or moving them. When a new block of transactions is being added, selecting which miner produces
the new block is based on the total Coin Age of all the coins that are being staked and the cryptographic problem. There are no block rewards, and
each miner receives a transaction fee. POS is faster, more resource-friendly, and energy efficient compared to POW. To improve the security of the
consensus mechanism, newer versions of POS include miners also staking a bet of coins on the validity of a block that is being added to the
blockchain. If the block is successfully (not successfully) appended, the miners will get a transaction fee proportionate to their bets (some or all of
their stake will be penalized/removed).
Difficulty
What is Ethereum difficulty?
Ethereum difficulty (or network difficulty) is a key value for every cryptocurrency. Ethereum Network difficulty is the difficulty of a problem that
miners must solve to find a block
Same thing when the number of miners decreases. When miners leave, the network hashrate goes down. Miners need more time to find a block. So
the network lowers its difficulty, thus making a problem easier to solve
Public & Private Blockchain
Online Wallet
Hardware Wallet
Paper Wallet
Trường hợp 1: User send transaction, recipient là contract address thì SMCT sẽ đc chạy
• After a contract is deployed, an EOA can execute functions defined in this contract.
Again it is implemented by sending an Ethereum transaction.
• ERC20 (Ethereum Request for Comment) là tên gọi của một bộ các tiêu chuẩn mà
những token được phát triển trên nền tảng blockchain của Ethereum phải tuân thủ theo
Tiêu chuẩn
ERC-20
3 quy tắc tùy chọn:
• Token Name: tên của token, ví dụ Marker
• Symbol: ký hiệu của token hay mã token, Maker có mã là MKR
• Decimals: Số thập phân (lên đến 18), quy định về số lượng chữ số thập phân trong đơn vị của
token. Decimals của MKR là 18, nghĩa là đơn vị nhỏ nhất của MKR là
0.000000000000000001 MKR.
For the approve & transferFrom workflow, two transactions are needed. Let’s say that
Alice wants to allow the AliceICO contract to sell 50% of all the AliceCoin tokens to
buyers like Bob and Charlie. First, Alice launches the AliceCoin ERC20 contract, issuing
all the AliceCoin to her own address. Then, Alice launches the AliceICO contract that can
sell tokens for ether. Next, Alice initiates the approve & transferFrom workflow. She
sends a transaction to the AliceCoin contract, calling approve with the address of the
AliceICO contract and 50% of the totalSupply as arguments. This will trigger the
Approval event. Now, the AliceICO contract can sell AliceCoin.
Ngoài ra thì có 1 số tool static analysis và chạy coverity như oyente (static analysis),
solidity coverage (coverity), cái này thì các dự án lớn sẽ cần, làm demo chơi chơi thì cũng
chưa cần tìm hiểu làm gì.
https://viblo.asia/p/xay-dung-ung-dung-dapps-dau-tien-cua-ban-oOVlYn0r58W
Dự án 1: Dự án 2:
Chò trơi mua vé số Dự đoán giá BTC, ETH, BNB trong chu kỳ Nphut
Tham khảo ứng dụng thực tiễn của Tham khảo ứng dụng thực tiển của Pancakeswap
Pancakeswap https://pancakeswap.finance/prediction
https://pancakeswap.finance/lottery Tham khảo logic SMCT của ứng dụng này (xem
Tham khảo logic SMCT của ứng dụng này (xem source code SMCT trên explorer của Binance)
source code SMCT trên explorer của Binance) Copy/Customize lại SMCT cho bài tập này
Copy/Customize lại SMCT cho bài tập này Phân tích và vẽ workflow cho Frontend Dapp
Phân tích và vẽ workflow cho Frontend Dapp Tiến tới code Dapp
Tiến tới code Dapp
ASIA BLOCKCHAIN CENTER
THANKS
Does anyone have any questions?
Follow the project updates