輕鬆看懂 Etherscan

CC Wang
Taipei Ethereum Meetup
8 min readJun 29, 2022

--

Photo by Marc Schulte on Unsplash

想要瀏覽 Ethereum 區塊鏈上面的公開資料,除了直接與節點互動之外,你還可以透過 blockchain explorer 來快速掌握所需資訊。

閱讀本文僅需對 Ethereum 有基礎的認識,並不需要任何撰寫程式的經驗。但是,筆者仍鼓勵讀者應額外深入探究各個欄位的設計哲學與原理,以達通盤了解各項架構之運作原理。

本文將透過截圖讓讀者了解 Etherscan 網頁羅列的各項數值之意涵,所有舉例的內容均可以自行覆核,且均為隨機挑選、無推銷單一專案之意圖。

若讀者需瀏覽圖片的高解析度版本,請參考這篇 HackMD 文章

Special thanks to Kevin Mai-Hsuan Chia and Jerry Ho for review and comment.

Block Page

假設我們想了解 block 14895081 發生了什麼事?您可以前往 Etherscan 首頁,並於搜尋框輸入數字做查詢,接著應能看到以下畫面:

Figure 1

① 顯示您正在看哪個 block number,點「<」和「>」可以切換不同 block

② 包裹這個 block 的 miner/proposer 提交的時間戳記,隨著使用的瀏覽器自動調整時區(此欄位原始資料為 Unix epoch 1654230140

③ 這個 block 與前一個 block 時間戳記的差值

④ 給 PoW miner 的固定獎勵(註:在 The Merge 後將取消這部分獎勵)

⑤ 這個 block 的所有 transaction fee 總和

⑥ 這個 block 的所有 burnt fee 總和(請參考 ⑩ 的說明)

⑦ 把這個區塊的 difficulty (註:在 The Merge 後將永遠是 0x0)加上前一個區塊的 total difficulty,就能得到這個區塊的 total difficulty

⑧ 把這個區塊的 gas used 除以 gas limit 就能得到 gas 實際消耗比例

⑨ 把這個區塊的 gas used 除以 15M gas,就能得到與 EIP-1559 設定之區塊 gas target 差異量的比例

⑩ 把 gas used 乘以 base fee per gas 就能得到 burnt fee 總和(EIP-1559 機制將區塊內所有 base fee 都燃燒掉,而非給予 miner;此欄位等於 ⑥)

⑪ 包裹這個 block 的 miner/proposer 提交的額外資訊(長度至多 32 bytes)

p.s.transaction 經常會簡寫成 txn,所以 txn fee 就是 transaction fee

接著,點擊網頁當中的「73 transactions」按鈕,將開啟另一個頁面,其表列出包含在這個 block 之內的所有 transaction 細節。

List of Transactions

新開啟的網頁表列出這個 block 所有 transaction 的細節:

Figure 2

① 如果 transaction hash 前面有「橙色」驚嘆號,代表它是 reverted transaction,錯誤發生在執行 internal transaction(message call)的過程

② 如果 transaction hash 前面有「紅色」驚嘆號,代表它是 reverted transaction,錯誤發生在執行 transaction 本身

③ 如果看到 transaction fee 後方有「綠色氣球」,代表 transaction 是以 type-2(EIP-1559)格式發送到 Ethereum 區塊鏈

④ 這個直行的數值代表 transaction 所攜帶的 ETH 數額(msg.value

⑤ 把這個直行的所有數字加總起來,就等於 Figure 1 當中的 ⑤

接著,點擊網頁當中的任意一條 transaction hash,將開啟另一個頁面顯示更多關於 transaction 的執行細節。(假設我們如圖所示點擊第一條 txn)

Transaction Page

關於 Figure 2 的第一條 transaction 細節,在下方 Figure 3 當中一覽無遺:

Figure 3

① Ethereum 最新 block number 與包含這條 txn 的 block number 的差異量

② 時間戳記的性質與 Figure 1 ② 相同

③ Etherscan 的伺服器首次發現這條 transaction 之後,經過多久時間這條 transaction 才被納入這個 block

④ 這個數值的性質與 Figure 2 ④ 相同

⑤ 把 (gas) usage by transaction 乘以 gas price 就能得到 transaction fee

⑥ 把 (gas) usage by transaction 乘以 base fee (per gas) 就能得到 burnt fee

⑦ 若 (Base fee + Max Priority fee) ≦ Max fee,則 gas price = (Base fee + Max Priority fee);反之,gas price = Max fee;非 EIP-1559 transaction 的 gas price 則由交易發起者指定,超過 Base fee 的份額才會交給 block miner/proposer

⑧ 把 (gas) usage by transaction 乘以 (Max fee - gas price) 就能得到transaction savings,意思是 EIP-1559 幫助交易發起者省下的錢 (關於 EIP-1559 的內容,請參考其他文章 [1, 2])

⑨ 此 txn 是發起者(tx.origin)從古至今發出的第幾筆(zero-indexed)

⑩ 這條 transaction 是 block 第七十三個被執行的交易(zero-indexed)

p.s. 可能有讀者想看看 gas price 在 ⑦ 的各種情況實例,請讀者參考這個 block 的 position 12、position 72 和 position 13 transaction。

怎麼計算 Base Fee Per Gas?

自從 London hard fork 之後,EIP-1559 改善原本使用者對設定 gas price 高低無所適從的情況,詳細內容請看其他 Taipei Ethereum Meetup 文章 [1, 2],或是由 Vitalik Buterin 撰寫的這篇文章

以下將用圖示解釋,上述範例怎麼獲得 base fee per gas 數值,一切的開頭請從 block 14895080 的 gas used 開始閱讀:

Figure 4

① 21,679,567 > 15,000,000

② Delta percentage = 21,679,597 ÷ 15,000,000 ≈ +44.5304%

③ (+44.5304%) × (+12.5%) ≈ +5.5663%

④ 44,479,108,103 Wei × (1+5.5663%) ≈ 46,954,966,827 Wei

⑤ Base fee (per gas) @ block 14895081= 46,954,966,827 Wei

如果區塊的 gas used 比起 15M gas target 少,那就把 factor 改成負 12.5%;如果剛好吻合 15M gas target,那麼 base fee per gas 將與前個 block 相同、保持不變。另外,每一個區塊的 gas used 天花板是 30M gas,而且每次 base fee per gas 升降不會超過 ±12.5% 的幅度。

Further reading

--

--