--- tags: it 鐵人賽 30 天, Web 3, ethereum --- # 從以太坊白皮書理解 web 3 概念 - Day4 ## Ethereum: Transaction 上一篇講到 EVM 與 Ethereum 節點的運作 今天來研究一下, Ethereum 中談論到 Transaction 的內容 ## 以 Transaction 的角度來說明 Ethereum Ethereum 可以被看做是是一個以 Transaction 為基底的狀態機。 Global State: 整個 Ethereum 的所有狀態 以下圖表是:  紅色的有向線代表 Transaction 而 Transaction 通常是蒐集數個為一個 Block 做打包 如下圖:  以狀態變化來看 Ethereum 可以當作是已時間為基準的狀態鏈接。如下圖:  從實作層面來看 Ethereum 可以當作是 Block 所形成的鏈,所以是 Blockchain 。  從帳本的角度來看 Ethereum 可以當作是 Transaction 的 Stack 。 因為查帳需要從最新的 Tranaction 往前查。 如下圖:  ## World State World State 是指整個區塊鏈的狀態。 內部儲存每個 Address 對應的 Account 狀態  ## Account 狀態 Account 狀態包含內容如下:  ## Account 類型 Account 分為 1. External Own Account 2. Contract Account 如下:   ## Address 類型 從 EOA 與 Contract 兩種 Account 都是以 address 形式在狀態中做紀錄 Address 是一個 160 bits 的值 加上前方 0x 兩個字元,假設用 hex 字元來表示,剛好是 42 個字元。 其推導方式如下:  ## Transaction Transaction 只能由 EOA 所交付。  ## Tranaction 分類 Transcation 分為兩類: 1. create contract: EOA 建立 Contract 2. message call: EOA 傳遞訊息給 Contract Account 或是另一個 EOA 如下圖:  以下兩個圖各自說明 Create Contract 與 Message Call 對 World State 的效果 1. Create Contract  2. Message Call  ## Transaction 內容 Transaction 內容基本包含以下幾個欄位: 1. nonce: 目前該 account 所累計的 Transaction 個數 2. gasPrice: 每個運算單元願意花多少 wei 去執行 3. gasLimit: 最多願意執行多少個運算單元 4. to: 接收方的地址。當 Create Contract 時,這個欄位帶 0 5. value: 要傳送的 balance 量,以 wei 為單位。 6. v, r, s: 做簽章所需要的初始值 7. data: 這個欄位根據 Transaction 類型放不同的值。當 Message Call 時,放 input data,當 Create Contract 時放 init code。  ## 參考文獻 [https://ethereum.org/en/whitepaper/#messages-and-transactions](https://ethereum.org/en/whitepaper/#messages-and-transactions) [https://www.quicknode.com/guides/knowledge-base/what-are-ethereum-transactions](https://www.quicknode.com/guides/knowledge-base/what-are-ethereum-transactions) [https://ethereum.org/en/developers/docs/transactions/](https://ethereum.org/en/developers/docs/transactions/) [https://takenobu-hs.github.io/downloads/ethereum_evm_illustrated.pdf](https://takenobu-hs.github.io/downloads/ethereum_evm_illustrated.pdf)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up