SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
Blockchain in Action
⽤朴素的技术视⻆介绍区块链的基本原理
Schubert Zhang

2020.03
What The F**k is The Blockchain?
区块链 是 互联⽹的⼆次⾰命
区块链
让我们从信息互联⽹跨越到价值互联⽹
通证(Token)
可流通的加密数字权益证明
基于区块链的各种价值表示物
通证经济(Token Economy)
别⼈跟我解释了N次,但还是没搞懂! Why?
听了多次演讲和交流,但还是⼀头雾⽔! Why?
看了⼏本讲“区块链”的书,每个字都认识,
但看完还是不知道是啥!Why?
What The F**k is The Blockchain?
(预备)
对于计算机和软件程序
你应该知道的⼏个基本概念
什么是计算机?
数据存储系统
(内存、硬盘)
计算系统
(CPU)
和外界联系的接⼝
(IO)
程序
(Program)
软件
控制系统
什么是软件程序?
DATA
数据
Methods
操作和改变数据的⽅法
编程语⾔
Language
if … else …
for (…)
…
⽹络时代
复杂系统
软件架构
CODE
图灵 + 冯·诺依曼
1930~1950
HASH / 哈希
抽象
数据结构
⾯向“对象”编程
⼏个计算机软件常识
f44b957d34d716edb52925d62a0965aae0452fd4d1e9a7c066523b4a586ccbb0
机器⼈程序 (Bot)
程序
(Bot)
交互
⼈
⽐特币 (Bitcoin)
相关的区块链技术
⽐特币概述
要解决什么问题:
• 传统交易⽅式,依赖银⾏等中央⾦融机构,作为第三⽅提供信⽤保障

• 交易双⽅需要更多信息公开,提⾼信任

• 交易的撤销和修改更容易在技术的达成,只要⾦融机构愿意
达成路径:
• 使⽤技术上已经很成熟的点对点去中⼼化⽹络

• 通过密码学技术保障资产的数字化转移、不可篡改和保护隐私 (私钥公钥加密和签名、Hash链)
那么问题来了,进⽽要解决⽆中⼼⽹络带来的技术复杂性问题:
• 解决因为⽆中⼼仲裁和协调,各节点⾃治保障数据⼀致性问题

• 保持底层数据结构简单扁平,⽆状态,数据模型极简,使⾃治和⼀致性更容易实现

• 解决因为⽹络延迟、丢包、中断、失序、甚⾄恶意等情况下的数据不⼀致性的恢复问题 (拜占庭将军问题)

• 通过激励⼿段,⿎励更多节点上线,以保障⾜够的计算机在⽹络上,实现存储和计算,使共识更有意义
解决易⽤性问题:
• 交易对⼿:地址之间,私钥->公钥 => “地址”

• 钱包:管理多个地址上的剩余资产(余额),便于操作
中本聪的那篇论⽂
⽐特币: ⼀种点对点电⼦货币系统
交易(合并和分隔交易额)
P2P⽹络
⼯作量证明 PoW (Proof of Work)
激励矿⼯,⽐特币发⾏
数据空间评估
隐私保护
Bitcoin System⼯作流程
交易(Transactions)达成的⼯作流程:
•新的交易被发起交易的那个节点向⽹络上所有节点⼴播通知;

•每个节点对收到的新交易通知进⾏验证,并按先后顺序归集到⼀个数据区块中(在内存中进⾏);

•当区块⼤⼩差不多(~1MB)或时间差不多(如10分钟)的时候,每个节点通过整个⽹络约定的⽅法选出⼀个节
点负责将数据持久化(连接到区块链上);⽐特币⽹络采⽤的是事先预定好的计算符合条件的Hash值(不断修
改区块中⼀个nonce字段的随机数,对数据库计算SHA256,要求Hash值前N位为0) ——这也被称作⼯作
量证明,也就是碰运⽓;

•当⼀个节点运⽓好竞争成功,就向所有节点⼴播这个数据块,请求连接到链上;

•其他节点验证收到的区块中的每⼀笔交易都有效且之前没有被⽀付过,就接受/确认这个区块;

•节点通过使⽤这个区块的哈希值作为上⼀个哈希值在链中创建下⼀个区块的⽅式表示对这个区块的接受。
区块链数据
区块链⽹络
数据库的磁盘
数据库的数据处理
对论⽂中的⼀些提醒:Timestamp
实际上这个timestamp并不是强调时间,⽽就是那个Block的SHA256 Hash值,或许叫做“指纹”更加合适。
最重要的技术基础:Asymmetric Encryption
Whitfield Diffie

(born 1944)
Martin Hellman
(born 1945)
2015 Turing Award
The citation for the award was: "For fundamental
contributions to modern cryptography. Diffie and
Hellman's groundbreaking 1976 paper, "New Directions
in Cryptography," introduced the ideas of public-key
cryptography and digital signatures, which are the
foundation for most regularly-used security protocols
on the internet today."
https://en.wikipedia.org/wiki/Whitfield_Diffie

https://en.wikipedia.org/wiki/Martin_Hellman
必须懂的加密安全技术:“加密” 和 “数字签名”
⾮对称加密:满⾜安全性和所有权验证的需求
私钥(Private Key):⾃⼰持有,不可泄露

公钥(Public Key):公开给所有需要与我通信的⼈
公钥加密:发送者先⽤对⽅公钥加密,接收者再⽤私钥解密
私钥签名:发送者先⽤私钥加密,接收者再⽤对⽅公钥解密验证其身份

(因为公钥是公开的,私钥加密没有加密作⽤,所以⼀般只加密数据的HASH摘要)
http://www.youdzone.com/signature.html

https://www.ruanyifeng.com/blog/2011/08/what_is_a_digital_signature.html

https://www.cnblogs.com/chengfengchi/p/11404355.html
1. 接收⽅能通过发送⽅的公钥认证发送⽅的身份;
2. 通过私钥签名,别⼈⽆法伪造我的身份,自⼰也不能抵赖;
3. 通过Hash Digest保证数据的完整性和不可篡改;
4. 数字签名在数字世界中实现了“见字如面”。
签名的作⽤:
(1) 确认发送者身份; (2) 保证数据不被篡改。
“加密” 和 “数字签名”:Two Principles
1. Any message encrypted with Bob’s public key
can only be decrypted with Bob’s private key.
2. Anyone with access to Alice’s public key can verify
that a message (signature) could only have been
created by Alice (with access to her private key).
Alice Bobmessage
交易(Bitcoin Transactions)原理和“价值传递”
交易表述 in the paper 更准确的解释
Notice that none of this requires an official third party to
authorize or authenticate the transactions. Alice, Bob, and Carol
can generate their own public-private key pairs without help from
third parties. Anyone who knows Alice's and Bob's public keys
can independently verify that the chain of signatures is
cryptographically valid. Digital signatures—combined with a few
innovations we'll discuss later—let people engage in banking
without needing a bank.
Hash
Owner 2’s
Public Key
Digest
Owner 1’s
Private Key
Owner 1’s
Signature
Encrypt
Owner 1
注:实际上,在⽐特币和区块链中,转账就叫“Send”
Bitcoin Transaction:多Input -> 多Output (⽐特币特有)
实际的⼀个交易允许多个输⼊(input)、多个输出(output)
A bitcoin transaction contains a list of inputs and outputs.
Each output has a public key associated with it.
For a later transaction to spend those coins, it needs an input with a
matching digital signature. 
https://bitcoin.org/en/how-it-works

https://arstechnica.com/tech-policy/2017/12/how-bitcoin-works/
https://www.blockchain.com
Address & Wallet
Derived from public key.
Hash fingerprint of public key.
Address
https://arstechnica.com/tech-policy/2017/12/how-bitcoin-works/

https://blog.csdn.net/waixingrenabc/article/details/82190566 (⽐特币地址是怎么计算出来的)
Address A
Address B
Address C
Wallet of Alice
Address D
Address F
Wallet of Bob
Private Key A
Public Key A
Private Key B
Public Key B
Private Key C
Public Key C
Private Key D
Public Key D
Private Key F
Public Key F
Transaction output to A
Transaction output to A
Transaction output to A
Transaction output to B
Transaction output to C
Transaction output to C
Transaction output to D
Transaction output to D
Transaction output to F
Transaction output to F
Wallet
Walle
https://www.blockchain.com/btc/address/3HqH1qGAqNWPpbrvyGjnRxNEjcUKD4e6ea
Transactions, UTXOs, Balances
Summary:
• The bitcoin blockchain does not hold account balances
• Bitcoin wallets hold keys (addresses) to UTXOs
• If included in a transaction, an entire UTXO is spent (in some cases
partially received back as “change” in the form of a brand new UTXO)
花钱原则:
1. 每⼀个交易的输⼊(input),都必须是前⾯某个交易的输出(output)
2. 前⾯某个交易的输出,只能被⽤(spend)⼀次 (double-spending problem)
3. 每次交易必须把前⾯的交易的输出bitcoins花完
4. 你可以把转账剩余的bitcoins拿出⼀⼩部分⽀付给矿⼯做交易费
5. 实在花不完的话,剩下的bitcoins在⽀付到⾃⼰钱包中的某个地址中
https://blockchain.info/tx/ae51116179e79bd6ecaf72fcdc743375a49467bfc219b114fb81d630ce31a00b
UTXO= Unspent Transaction Output
UTXOs和交易时对UTXOs的检查
同时解决了双花问题(double-spending problem)
https://www.jianshu.com/p/aebf0e4174ad
https://medium.com/cybermiles/diving-into-ethereums-world-state-c893102030ed
https://hackernoon.com/getting-deep-into-ethereum-how-data-is-stored-in-ethereum-e3f669d96033
Bitcoin’s Blockchain
共享的公共账本 (shared public ledger)
每个节点都存⼀样的全部的交易记录数据
includes a list of
transactions
flush
https://www.blockchain.com/explorer
链状结构增加攻击难度
挖矿和矿⼯ Mining
激励:为什么有⼈愿意把⾃⼰的计算机当矿⼯?
奖励Bitcoin,⿎励更多节点加⼊,提供计算能⼒,⾜够多的节点才能构建⼀
个可靠的⾃治系统。

货币发⾏:
激励⽐特币的同时,搞定了货币发⾏问题。
矿⼯节点⼲的活:
• 接受和收集交易记录

• 检查交易的合法性

• 将收集到的交易记录按序组装成区块

• 暴⼒计算符号要求的区块HASH值

• 将区块持久化存储上链
中国的⽐特币矿场和矿机产业
嘉楠科技
⽐特⼤陆
防⽌攻击
冲突解决的原则:继承最⻓的链
恶意攻击者必须有超过⼤多数的算⼒才有可能制造假交易https://arstechnica.com/tech-policy/2017/12/how-bitcoin-works/
如果让我⾃⼰设计Bitcoin的软件架构?
矿⼯节点的主要⼯作
⾃⼰设想的架构:
nonce
⼤多数传统数据库的内部实现
MySQL
Google Bigtable
HBase
Cassandra
…
Client
Peer to Peer Network
每个节点只需要知道⽹络中的少数⼏个节点
即可连接到整张⽹络
Client-Server vs. Peer-to-Peer
Client
Server
Client
Server
Client
Server
Client
Server
Client
Server
Client
Server
Bitcoin in summary
数据存储上:本质是⼀个数据库,和我们存储⽇志是类似⼀回事
交易表示上:⽤⾮对称加密的数字签名技术安全地表达了资产的转移
实质上类似⽤数据签名做消息发送
巧妙地利⽤了这⼏种技术同时搞定了⼏件事:
数字签名做资产转移和验证

Hash和数据链保证更不容易篡改和攻击

计算Hash的同时做⼯作量证明

挖矿的同时做了货币发⾏,同时⼜⽤发⾏的新币激励这个挖矿者,带动更多节点参与

这是因为在bitcoin这个系统上,没有承载任何其他应⽤和实际的资产(空⽓币)

bitcoin的成功,在于它的交易,不需要任何第三⽅(特别是实体资产托管⽅)的参与,即交易对⼿⻛险很低

问题:
P2P⽹络,要达成和确认⼀笔交易,速度很慢

每个full node存储所有数据,可持续空间有限(尽管bitcoin本身交易数据⼤⼩有限)

做PoW浪费电⼒,因为挖矿有利可图,越来越多算⼒/能源参与,但没有创造实际经济价值

⽐特币是从空⽓中创造出来的极客玩具,他不和任何实际资产挂钩,但仅此⽽已

更多是⼀种理想主义意识形态

So far, that hasn't really happened. Almost nine years after its creation, bitcoin usage is still confined to a
small minority of bitcoin and cryptocurrency hobbyists. ——> 币圈
参考资料
⼊⻔资料:
《⽐特币和区块链基本原理-李永乐》

https://www.youtube.com/watch?v=g_fSistU3MQ

《⽐特币⼊⻔教程-阮⼀峰》

https://www.ruanyifeng.com/blog/2018/01/bitcoin-tutorial.html

《How bitcoin works》

https://arstechnica.com/tech-policy/2017/12/how-bitcoin-works/
建议看官⽅资料和深度解释,别去看市⾯上的中⽂书籍和各种博客⽂章:
《原始论⽂》

https://bitcoin.org/en/bitcoin-paper

《官⽅⽹站》

https://bitcoin.org/

《实际数据浏览和观察探索》

https://www.blockchain.com/explorer

《Bitcoin Wiki》

https://en.bitcoin.it/wiki/Main_Page

《实际操作钱包和交易》

https://www.bitcoin.com

《The Basics of Bitcoins and Blockchains: An Introduction to Cryptocurrencies and the Technology that Powers Them》

https://bitsonblocks.net/
以太坊 (Ethereum)
Bitcoin: a shared world ledger, world wide ledger
Ethereum: a shared world computing platform, world computer
Ethereum Explorer
https://etherscan.io/
每约14秒⼀个block
每天6000+ blocks
每个block只有⼏KB~⼏⼗KB
每个block中只有⼏个~⼏百个
transactions
每天有⼏⼗万~百万的新
transactions
每天有⼏万~⼗万的新
addresses/accounts
Block List
(block很⼩, 写很快)
Transactions List
(每个transaction的from/to地址唯⼀)
Block Internal
Transaction Internal
以太坊是什么?
区块链基础设施
和电⼦货币系统
全球共享的计算机系统
表达价值的软件应⽤
或其他应⽤
以太坊和以太币
最基础的交易
Blockchain
智能合约
Smart Contract
TOKEN
(通证)
和⽐特币类似的基础设施
建⽴了区块链、⽆中⼼⽹络、挖矿和激励机等制
区块链和抽象的交易(⼀切皆交易)
作为交易费⽤(燃料)的以太币流通
在基础设施上可以跑⽤户⾃编程的程序
每个节点都可能被调度执⾏该程序(叫做智能合约)
在智能合约的基础上
定义某种智能合约(TOKEN)的标准模板
实现以太币以外的智能资产的的发⾏、表达和交易
可以让资产上链数字化表示
资产在链上交易流通
可以部署程序到⽹络上
需要的时候发指令,调⽤这个
程序执⾏
外界只能通过底层的发交易数
据和智能合约交互
可以挖矿
以太币ETH像BTC⼀样值钱
可以交易ETH
要消耗ether
要消耗ether本质上是定义标准接⼝的程序(如ERC20标准)
本质上就是⼀段程序,部署在区块链上
本质上和⽐特币类似 要消耗ether
以太坊的三个能⼒层次
第⼀层能⼒:和⽐特币⼀样的以太币发⾏和交易 (Blockchain Transaction)
可以挖矿(获得激励以太币)、转账交易,所有⼀切都是从A地址到B地址,逻辑上⽐特币的多输出多输出更简单,通过底层区块
链构建了共享账本 (a shared world ledger, world wide ledger)。同时这个底层区块链数据层,也为后⾯的外界和智能合约程序交
互建⽴了唯⼀的数据(消息)通道。
第⼆层能⼒:智能合约(Smart Contract)
这是他的核⼼能⼒,⽬标是打造去中⼼化的,世界共享的共享计算机 (a shared world computing platform, world computer),
任何⼈的程序执⾏需求都可以⾃⾏编写代码并提交上链,然后当被调⽤时⽹络共识选择⼀个节点帮你执⾏。所谓智能合约,可以理
解为我们⼯程师平时都理解的程序bot (例如钉钉机器⼈),所以他也归⼀个账户地址(就跟⼀个实际的⼈⼀样—-机器⼈)。你给它
发个消息,触发它执⾏⼀段代码。这段程序还会维护⼀些变量数据,这些数据是同步存储到全⽹节点的。
第三层能⼒:TOKEN/通证 (可流通的数字权益证明)
其实就是智能合约上的有规范的应⽤,也就是给上述那种Bot定义了标准的数据变量和接⼝(Interface),就像给⼀个类定义标准的
Interface,Interface规定了类似转账、授权额度、发⾏等相关接⼝。任何⼈都可以继承和实现这个标准接⼝(如ERC20、
ERC777标准),发⾏⾃⼰的TOKEN。实际就是把这个标准接⼝的智能合约代码部署到链上,初始化给你⾃⼰或某个地址⼀些
TOKEN额度,然后就可以通过调⽤这个智能合约的⽅法进⾏操作,例如转⼀些TOKEN给其他⼈了。
数据结构
https://pegasys.tech/ethereum-explained-merkle-trees-world-state-transactions-and-more/
https://kauri.io/ethereum-explained-merkle-trees-world-state-transa/1f4196c3db7f41e5845f063dc1581a4e/a
https://hackernoon.com/getting-deep-into-ethereum-how-data-is-stored-in-ethereum-e3f669d96033
https://medium.com/cybermiles/diving-into-ethereums-world-state-c893102030ed
address1 balance1, storageRoot1, codeHash1, nonce
address2 balance2, storageRoot2, codeHash2, nonce
address3 balance3, storageRoot3, codeHash3, nonce
…
…
World
State
balanceN, storageRootN, codeHashN, nonce
Storage
ephemeral & constantly updating
stateRoot
address1 smart contract data
address2 smart contract data
address3 smart contract data
…
…
smart contract data
storageRoot1
storageRoot2
storageRoot3
storageRootN
ephemeral & constantly updating
智能合约数据
ephemeral
随着合约程序执⾏持续更新
每个地址账户有⼀个storage结构
全局的状态数据
ephemeral
随着交易的上链持续更新
内部结构是Key-Value,每个地址账户⼀个状态结构
交易回执数据
permanent
每个交易⼀条数据
每个block有个结构
交易数据
permanent
每个交易⼀条数据
每个block有个结构
1. The world state trie contains the mapping between addresses and account
states. The hash of the root node of the world state trie is included in a block (in the
stateRoot field) to represent the current state when that block was created. We have
only one world state trie.

2. The account storage trie contains the data associated to a smart contract. The
hash of the root node of the Account storage trie is included in the account state (in
the storageRoot field). We have one Account storage trie for each account.

3. The transaction trie contains all the transactions included in a block. The hash of
the root node of the Transaction trie is included in the block header (in the
transactionsRoot field). We have one transaction trie per block.

4. The transaction receipt trie contains all the transaction receipts for the
transactions included in a block. The hash of the root node of the transaction
receipts trie is included in also included in the block header (in the receiptsRoot field);
We have one transaction receipts trie per block.
Blockchain
permanent
Block中的stateRoot
只是当时瞬间的快照
Block中的transactionRoot和receiptsRoot
代表了不可变的Transactions和Receipts
https://ethereum.stackexchange.com/questions/268/ethereum-block-architecture
以太币 ETH / Ether
以太坊的以太币实际上和⽐特币没有本质区别
但以太坊实现了⼀个分布式共享计算机系统
⽽以太币被⽤来⽀付帮你将交易写⼊区块持久化,以及帮你计算代码(智能合约)的机器的费⽤
所谓“燃料”币
发起交易时,钱包客户端提示付费
Account / Address / Wallet
两类账户/地址:
1. 只储存着以太币的账户/地址:Externally Owned Accounts (EOA),和⽐特币的地址差不多,也成为“外部账户”。An EOA account
is the account that you and I would have, that we can use to send Ether to one another and deploy smart contracts.

2. 合约的账户/地址:Contract Accounts (CA),也就是“机器⼈”的地址. A contract account is the account that is created when a
smart contract is deployed. Every smart contract has its own Ethereum account address. 存有代码(并可能存储着 ETH 或其它
Token)的账户。智能合约上传后,其代码就⼀直保存在以太坊系统上,等待着被调⽤激活使⽤。
这两种账户都会有相应的私钥,私钥持有者就可以⽤私钥来签发该账户的交易。
An Externally Owned Account A Contract Account
MetaMask, Wallet
共识和⼀致性
以太坊使⽤PoW,PoS还未实⾏
以太坊出块时间14秒(14秒写⼀次数据库),⽐特币是10分钟
单块数据量⼤⼩是⼏百 KB。
以太坊⽤衡量交易和智能合约计算复杂度的单位来标示区块的⼤⼩,这个⼤⼩被称为 “区块 Gas 上限”,⽽且区块 Gas
上限可以逐块变化(⽐特币的区块⼤⼩上限是⼀定的)。⽬前以太坊区块的 Gas 上限已达到 900 万 Gas。
ETH发⾏,区块奖励
发起交易者需要⾃⼰为交易设置 Gas 价格(即愿意为每单位 Gas ⽀付多少费⽤),这个 Gas Price 会成为矿⼯选择是否
打包该交易的依据之⼀。因为⼈们对交易的需求不是时时都⼀样的,Gas Price 也会随当前⼈们对交易上链需求的改变⽽
波动。
以太坊的 “交易”
Transactions:
在⽐特币区块链上主要是指⽐特币的转账交易,⽽在以太坊上则更为多样,主
要包括三类 :
1. ETH 的转账 (和⽐特币类似):Transactions that transfer value between
two EOAs (e.g., change the sender and receiver account balances)

2. 部署智能合约:Transactions that deploy a contract (therefore, create an
account, the contract account)。 

3. ⽤户与智能合约的交互:Transactions that send a message call to a
contract (e.g., set a value in the smart contract by sending a message call
that executes a setter method)

4. 智能合约所发⾏TOKEN的转移: Transactions that transfer tokens between
two EOAs.
以太坊交易和智能合约的抽象:所有业务形态在以太坊的区块链上,都抽象成
blockchain在上完成⼀笔交易
1. 在区块链数据库上,存储统⼀的数据结构的记录,记录中数据格式是⼀笔交易;
2. 把所有⾏为都抽象成交易:⼀个真正的交易、创建⼀个合约、调⽤(触发)合约中
的某个⽅法等,都抽象成底层数据库中的交易
3. 这就像微信在其聊天通道中,把所有其中东西都抽象成消息⼀样,⽐如微信转账
也是⼀个消息。
4. 从另⼀个⾓度讲,我们可以把transactions构成的blockchain看做是⼀个持续
append的⽇志;
智能合约(Smart Contract)
每个节点上都有个虚拟机环境:EVM
智能合约编程语⾔:Solidity —— 类似JavaScript
智能合约是储存(部署)在以太坊区块链上的⼩程序(机器⼈代码)
⼀段部署在区块链上的代码,可以被区块链⽹络上的计算节点执⾏,并且可更新账本
区块链提供了可信存储,智能合约提供了可信计算。
在以太坊中,你可以写⼀段程序,将其部署到区块链上(部署的时候以太坊会给他创建⼀个账户),从⽽建⽴
⼀个智能合约。

这个程序可以定义多种类型的变量,占⽤存储空间,定义Public的接⼝供外界调⽤。

调⽤这些接⼝就像发送消息给这个地址(抽象成创建⼀笔交易),

激活/调⽤⼀个智能合约时,你等于是请求整个⽹络中的矿⼯来执⾏合约中的计算⼯作。这会花费矿⼯的时间和
能源,⽤户理所当然得给他们报酬。Gas 就是⽀付服务费的机制。
客户端 服务器
部署程序
调⽤
(通过API或MQ)
返回
(通过API或MQ)
更新
数据库
地址A 地址B
调⽤
(通过区块链交易)
部署程序
(通过区块链交易)
更新
合约⾃定义数据
地址C
调⽤
(通过区块链交易)
传统互联⽹程序的执⾏
智能合约
智能合约 (Smart Contract)
智能合约实质上是⼀套以数字形式定义的承诺(Promises),包括合约参与⽅可以在上⾯执⾏这些承诺的协议。
⽤⼀段程序来实现它。
智能合约
部署在区块链⽹络上的⼀段程序
A B
C
A B C
区块链交易 区块链交易 区块链交易
智能合约(Smart Contract)
https://my.oschina.net/u/3843525/blog/1800800
https://my.oschina.net/u/3843525/blog/1800826
智能合约开发环境
Remix (Ethereum IDE http://remix.ethereum.org/) + MetaMask (chrome-extension) + etherscan.io(测试环境)
TOKEN
玩具反⽃城
TOKEN
https://github.com/ConsenSys/Token-Factory
在以太坊上表示某种资产:
1. 资产的总供应量

2. 资产对不同账户的授信额度

3. 某个账户(地址)的持有量

4. 资产的价值转移 …
TOKEN引擎程序的本质
还是智能合约:
发⾏⾃⼰的TOKEN
发⾏⾃⼰的TOKEN
部署TOKEN合约
TOKEN名称为SchubertCoin,发⾏100个 给某个账户授信approve了10个TOKEN
https://www.jianshu.com/p/ce9417905b97
给那个账户转2个TOKEN
https://blog.csdn.net/tian_qing_lei/article/details/81357100
Demo Time
(explorer, smart contract, token)
The Ethereum Yellow Paper
还是要把这个Paper读⼀下,避免被各种博客⽂章和不靠谱的书带偏
⾃⼰部署以太坊私链
https://blog.csdn.net/zg_hover/article/details/82080958
https://blog.csdn.net/zg_hover/article/details/82081572
https://www.jianshu.com/p/406e9ba9985f
https://www.ucloud.cn/yun/24645.html
geth --datadir data0 account new
geth --datadir data0 init genesis.json
geth --datadir data0 --networkid 1000 --rpc console --port 30304 --rpcport 8546 --allow-insecure-unlock
eth.blockNumber
eth.getBalance(eth.accounts[0])
eth.getBalance(eth.accounts[1])
eth.getBlock(1)
eth.accounts
personal.newAccount("password")
web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
personal.unlockAccount(eth.accounts[0])
amount = web3.toWei(10,'ether')
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:amount})
txpool.status
txpool.inspect.pending
web3.fromWei(eth.getBalance(eth.accounts[1]),'ether')
miner.start(1);admin.sleepBlocks(1);miner.stop()
eth.getTransaction("0xbc4dc435ad87aedfa7ff5cf6e9111f9b6043a2421326d02b13c437ef14c01828”)
我们也可以下载⼀个以太坊的节点软件,⾃⼰在电脑上安装和尝试,右下⻆⽂章可参考
参考资料
最好的学习资料:
https://www.ethereum.org/

以太⽹Explorer:
https://etherscan.io/

概念:
以太坊简介:https://ethfans.org/posts/gentle-introduction-ethereum-new-version-with-more-note

什么是以太坊简介:https://ethfans.org/posts/what-is-ethereum

以太坊创始⼈的解答:https://coincenter.org/entry/what-is-ethereum, 中⽂: https://zhuanlan.zhihu.com/p/20636823

Book: 《Mastering Ethereum: Building Smart Contracts and DApps》
To be continue …

Contenu connexe

Tendances

区块链原理
区块链原理区块链原理
区块链原理Noah Chen
 
区块链与金融科技的未来
区块链与金融科技的未来区块链与金融科技的未来
区块链与金融科技的未来Wanfeng Chen
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201Benson Sun
 
区块链对出版国际化的创新意义及应用展望
区块链对出版国际化的创新意义及应用展望区块链对出版国际化的创新意义及应用展望
区块链对出版国际化的创新意义及应用展望Xiaofeng Chen
 
Blockchain 101 for nccu
Blockchain 101 for nccuBlockchain 101 for nccu
Blockchain 101 for nccuBenson Sun
 
大数据及区块链应用驱动下之互联网金融商业模式
大数据及区块链应用驱动下之互联网金融商业模式大数据及区块链应用驱动下之互联网金融商业模式
大数据及区块链应用驱动下之互联网金融商业模式Emil Chan
 
區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用Jacob Lee
 
比特币与区块链
比特币与区块链比特币与区块链
比特币与区块链haipome
 
線上區塊鏈投票.pdf
線上區塊鏈投票.pdf線上區塊鏈投票.pdf
線上區塊鏈投票.pdfBrownWood28
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介Nicholas Lin
 
Smart Contract Automation Test
Smart Contract Automation Test Smart Contract Automation Test
Smart Contract Automation Test Louis Liao
 
Using Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainUsing Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainKaichao Sun
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharingLman Chu
 
Polkadot 治理
Polkadot 治理Polkadot 治理
Polkadot 治理Anson Lau
 
區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)Nic Lin
 
20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_BlockchainCollaborator
 
從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術Will Huang
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlokcert
 
金融革命?談區塊鏈上的去中心化金融應用
金融革命?談區塊鏈上的去中心化金融應用金融革命?談區塊鏈上的去中心化金融應用
金融革命?談區塊鏈上的去中心化金融應用Yao-Wei Ou
 
投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈Yao-Wei Ou
 

Tendances (20)

区块链原理
区块链原理区块链原理
区块链原理
 
区块链与金融科技的未来
区块链与金融科技的未来区块链与金融科技的未来
区块链与金融科技的未来
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201
 
区块链对出版国际化的创新意义及应用展望
区块链对出版国际化的创新意义及应用展望区块链对出版国际化的创新意义及应用展望
区块链对出版国际化的创新意义及应用展望
 
Blockchain 101 for nccu
Blockchain 101 for nccuBlockchain 101 for nccu
Blockchain 101 for nccu
 
大数据及区块链应用驱动下之互联网金融商业模式
大数据及区块链应用驱动下之互联网金融商业模式大数据及区块链应用驱动下之互联网金融商业模式
大数据及区块链应用驱动下之互联网金融商业模式
 
區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用區塊鏈科技趨勢與應用
區塊鏈科技趨勢與應用
 
比特币与区块链
比特币与区块链比特币与区块链
比特币与区块链
 
線上區塊鏈投票.pdf
線上區塊鏈投票.pdf線上區塊鏈投票.pdf
線上區塊鏈投票.pdf
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介
 
Smart Contract Automation Test
Smart Contract Automation Test Smart Contract Automation Test
Smart Contract Automation Test
 
Using Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp ChainUsing Substrate to Develop a DApp Chain
Using Substrate to Develop a DApp Chain
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharing
 
Polkadot 治理
Polkadot 治理Polkadot 治理
Polkadot 治理
 
區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)區塊鏈懂不懂 (2020/01/02 快樂學程式)
區塊鏈懂不懂 (2020/01/02 快樂學程式)
 
20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain20161125_新趨勢報告_Blockchain
20161125_新趨勢報告_Blockchain
 
從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for Lawyers
 
金融革命?談區塊鏈上的去中心化金融應用
金融革命?談區塊鏈上的去中心化金融應用金融革命?談區塊鏈上的去中心化金融應用
金融革命?談區塊鏈上的去中心化金融應用
 
投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈
 

Similaire à Blockchain in Action

Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Tom Yang
 
20181120 NISRA - 密碼學沒有入門
20181120 NISRA - 密碼學沒有入門20181120 NISRA - 密碼學沒有入門
20181120 NISRA - 密碼學沒有入門Chao An Hsiao
 
區塊鏈與金融科技(Blockchain and Fintech)
區塊鏈與金融科技(Blockchain and Fintech)區塊鏈與金融科技(Blockchain and Fintech)
區塊鏈與金融科技(Blockchain and Fintech)HO-HSUN LIN
 
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)張大明 Ta-Ming Chang
 
《氪月报》2011年12月
《氪月报》2011年12月《氪月报》2011年12月
《氪月报》2011年12月Chada Chiu
 
因太區塊鏈-探索區塊鏈投資.pdf
因太區塊鏈-探索區塊鏈投資.pdf因太區塊鏈-探索區塊鏈投資.pdf
因太區塊鏈-探索區塊鏈投資.pdf因太區塊鏈
 
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of Culture
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of CultureSELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of Culture
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of CultureJu Chun Ko
 
Io t security-ameba-ppt
Io t security-ameba-pptIo t security-ameba-ppt
Io t security-ameba-pptJou Neo
 
簡單小步驟,輕鬆觀賞 Virtual Show
簡單小步驟,輕鬆觀賞 Virtual Show簡單小步驟,輕鬆觀賞 Virtual Show
簡單小步驟,輕鬆觀賞 Virtual Showadvantech2012
 
NFT 与数字商品的未来
NFT 与数字商品的未来NFT 与数字商品的未来
NFT 与数字商品的未来Jedi Lu
 
A tour of ethereum ecosystem
A tour of ethereum ecosystemA tour of ethereum ecosystem
A tour of ethereum ecosystemChang-Wu Chen
 
Spirent_securityLab-服務介紹_2022.pdf
Spirent_securityLab-服務介紹_2022.pdfSpirent_securityLab-服務介紹_2022.pdf
Spirent_securityLab-服務介紹_2022.pdfssuserdfa916
 
人人能編程是可能的嗎?
人人能編程是可能的嗎?人人能編程是可能的嗎?
人人能編程是可能的嗎?Fred Lin
 
ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟InfiniteChain
 
电子杂志(试刊)
电子杂志(试刊)电子杂志(试刊)
电子杂志(试刊)ProCharm
 
物聯網應用全貌以及微軟全球案例
物聯網應用全貌以及微軟全球案例物聯網應用全貌以及微軟全球案例
物聯網應用全貌以及微軟全球案例Herman Wu
 
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on KubernetesBuild the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetesinwin stack
 
Powerpoint SHOW
Powerpoint SHOWPowerpoint SHOW
Powerpoint SHOWoyag
 

Similaire à Blockchain in Action (20)

Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁
 
20181120 NISRA - 密碼學沒有入門
20181120 NISRA - 密碼學沒有入門20181120 NISRA - 密碼學沒有入門
20181120 NISRA - 密碼學沒有入門
 
區塊鏈與金融科技(Blockchain and Fintech)
區塊鏈與金融科技(Blockchain and Fintech)區塊鏈與金融科技(Blockchain and Fintech)
區塊鏈與金融科技(Blockchain and Fintech)
 
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)
無限想像的科技創新未來—大數據專案管理與資料分析實務應用 20170927(龍華科技大學)
 
《氪月报》2011年12月
《氪月报》2011年12月《氪月报》2011年12月
《氪月报》2011年12月
 
因太區塊鏈-探索區塊鏈投資.pdf
因太區塊鏈-探索區塊鏈投資.pdf因太區塊鏈-探索區塊鏈投資.pdf
因太區塊鏈-探索區塊鏈投資.pdf
 
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of Culture
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of CultureSELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of Culture
SELF TOKEN 區塊鏈前瞻科技於文化娛樂產業之發展現況 以亞洲首部區塊鏈電影《聖人大盜》及全球各地應用為例 @ Ministry of Culture
 
Io t security-ameba-ppt
Io t security-ameba-pptIo t security-ameba-ppt
Io t security-ameba-ppt
 
簡單小步驟,輕鬆觀賞 Virtual Show
簡單小步驟,輕鬆觀賞 Virtual Show簡單小步驟,輕鬆觀賞 Virtual Show
簡單小步驟,輕鬆觀賞 Virtual Show
 
NFT 与数字商品的未来
NFT 与数字商品的未来NFT 与数字商品的未来
NFT 与数字商品的未来
 
A tour of ethereum ecosystem
A tour of ethereum ecosystemA tour of ethereum ecosystem
A tour of ethereum ecosystem
 
Spirent_securityLab-服務介紹_2022.pdf
Spirent_securityLab-服務介紹_2022.pdfSpirent_securityLab-服務介紹_2022.pdf
Spirent_securityLab-服務介紹_2022.pdf
 
人人能編程是可能的嗎?
人人能編程是可能的嗎?人人能編程是可能的嗎?
人人能編程是可能的嗎?
 
ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟ICO、智能合約與代幣經濟
ICO、智能合約與代幣經濟
 
Bitcoin(bc)
Bitcoin(bc)Bitcoin(bc)
Bitcoin(bc)
 
Blockchain
BlockchainBlockchain
Blockchain
 
电子杂志(试刊)
电子杂志(试刊)电子杂志(试刊)
电子杂志(试刊)
 
物聯網應用全貌以及微軟全球案例
物聯網應用全貌以及微軟全球案例物聯網應用全貌以及微軟全球案例
物聯網應用全貌以及微軟全球案例
 
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on KubernetesBuild the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
 
Powerpoint SHOW
Powerpoint SHOWPowerpoint SHOW
Powerpoint SHOW
 

Plus de Schubert Zhang

Engineering Culture and Infrastructure
Engineering Culture and InfrastructureEngineering Culture and Infrastructure
Engineering Culture and InfrastructureSchubert Zhang
 
Simple practices in performance monitoring and evaluation
Simple practices in performance monitoring and evaluationSimple practices in performance monitoring and evaluation
Simple practices in performance monitoring and evaluationSchubert Zhang
 
Scrum Agile Development
Scrum Agile DevelopmentScrum Agile Development
Scrum Agile DevelopmentSchubert Zhang
 
Engineering practices in big data storage and processing
Engineering practices in big data storage and processingEngineering practices in big data storage and processing
Engineering practices in big data storage and processingSchubert Zhang
 
Bigtable数据模型解决CDR清单存储问题的资源估算
Bigtable数据模型解决CDR清单存储问题的资源估算Bigtable数据模型解决CDR清单存储问题的资源估算
Bigtable数据模型解决CDR清单存储问题的资源估算Schubert Zhang
 
Big Data Engineering Team Meeting 20120223a
Big Data Engineering Team Meeting 20120223aBig Data Engineering Team Meeting 20120223a
Big Data Engineering Team Meeting 20120223aSchubert Zhang
 
HBase Coprocessor Introduction
HBase Coprocessor IntroductionHBase Coprocessor Introduction
HBase Coprocessor IntroductionSchubert Zhang
 
Hadoop大数据实践经验
Hadoop大数据实践经验Hadoop大数据实践经验
Hadoop大数据实践经验Schubert Zhang
 
Wild Thinking of BigdataBase
Wild Thinking of BigdataBaseWild Thinking of BigdataBase
Wild Thinking of BigdataBaseSchubert Zhang
 
RockStor - A Cloud Object System based on Hadoop
RockStor -  A Cloud Object System based on HadoopRockStor -  A Cloud Object System based on Hadoop
RockStor - A Cloud Object System based on HadoopSchubert Zhang
 
Hadoop compress-stream
Hadoop compress-streamHadoop compress-stream
Hadoop compress-streamSchubert Zhang
 
Ganglia轻度使用指南
Ganglia轻度使用指南Ganglia轻度使用指南
Ganglia轻度使用指南Schubert Zhang
 
DaStor/Cassandra report for CDR solution
DaStor/Cassandra report for CDR solutionDaStor/Cassandra report for CDR solution
DaStor/Cassandra report for CDR solutionSchubert Zhang
 
Learning from google megastore (Part-1)
Learning from google megastore (Part-1)Learning from google megastore (Part-1)
Learning from google megastore (Part-1)Schubert Zhang
 
Hanborq optimizations on hadoop map reduce 20120221a
Hanborq optimizations on hadoop map reduce 20120221aHanborq optimizations on hadoop map reduce 20120221a
Hanborq optimizations on hadoop map reduce 20120221aSchubert Zhang
 

Plus de Schubert Zhang (20)

Engineering Culture and Infrastructure
Engineering Culture and InfrastructureEngineering Culture and Infrastructure
Engineering Culture and Infrastructure
 
Simple practices in performance monitoring and evaluation
Simple practices in performance monitoring and evaluationSimple practices in performance monitoring and evaluation
Simple practices in performance monitoring and evaluation
 
Scrum Agile Development
Scrum Agile DevelopmentScrum Agile Development
Scrum Agile Development
 
Career Advice
Career AdviceCareer Advice
Career Advice
 
Engineering practices in big data storage and processing
Engineering practices in big data storage and processingEngineering practices in big data storage and processing
Engineering practices in big data storage and processing
 
HiveServer2
HiveServer2HiveServer2
HiveServer2
 
Horizon for Big Data
Horizon for Big DataHorizon for Big Data
Horizon for Big Data
 
Bigtable数据模型解决CDR清单存储问题的资源估算
Bigtable数据模型解决CDR清单存储问题的资源估算Bigtable数据模型解决CDR清单存储问题的资源估算
Bigtable数据模型解决CDR清单存储问题的资源估算
 
Big Data Engineering Team Meeting 20120223a
Big Data Engineering Team Meeting 20120223aBig Data Engineering Team Meeting 20120223a
Big Data Engineering Team Meeting 20120223a
 
HBase Coprocessor Introduction
HBase Coprocessor IntroductionHBase Coprocessor Introduction
HBase Coprocessor Introduction
 
Hadoop大数据实践经验
Hadoop大数据实践经验Hadoop大数据实践经验
Hadoop大数据实践经验
 
Wild Thinking of BigdataBase
Wild Thinking of BigdataBaseWild Thinking of BigdataBase
Wild Thinking of BigdataBase
 
RockStor - A Cloud Object System based on Hadoop
RockStor -  A Cloud Object System based on HadoopRockStor -  A Cloud Object System based on Hadoop
RockStor - A Cloud Object System based on Hadoop
 
Fans of running gump
Fans of running gumpFans of running gump
Fans of running gump
 
Hadoop compress-stream
Hadoop compress-streamHadoop compress-stream
Hadoop compress-stream
 
Ganglia轻度使用指南
Ganglia轻度使用指南Ganglia轻度使用指南
Ganglia轻度使用指南
 
DaStor/Cassandra report for CDR solution
DaStor/Cassandra report for CDR solutionDaStor/Cassandra report for CDR solution
DaStor/Cassandra report for CDR solution
 
Big data and cloud
Big data and cloudBig data and cloud
Big data and cloud
 
Learning from google megastore (Part-1)
Learning from google megastore (Part-1)Learning from google megastore (Part-1)
Learning from google megastore (Part-1)
 
Hanborq optimizations on hadoop map reduce 20120221a
Hanborq optimizations on hadoop map reduce 20120221aHanborq optimizations on hadoop map reduce 20120221a
Hanborq optimizations on hadoop map reduce 20120221a
 

Blockchain in Action