【試讀版】All In One Solidity
KrypltoCampChiHaoLu
  • Welcome!
  • | Chapter 0 | Intro
    • 【推薦序】
    • 【前言】
  • Part I Basic
    • | Chapter 1 | 基本介紹 Introduction
      • 【環境建置 Remix IDE】
      • 【版本控制】
      • 【Hello World & First Contract】
      • 【Practice】
      • 【Answer】
    • | Chapter 2 | 型別 Types & 變數 Variables
      • 【Integer】
      • 【Bool】
      • 【Address】
      • 【Contract & This】
      • 【String】
      • 【Scope】
      • 【Practice】
      • 【Answer】
    • | Chapter 3 | 單位 Unit & 運算子 Operators
      • 【單位】
      • 【Time】
      • 【運算子】
      • 【Practice】
      • 【Answer】
    • | Chapter 4 | 流程控制 Selection and Repetition
      • 【If-Else】
      • 【For】
      • 【While】
      • 【Practice】
      • 【Answer】
    • | Chapter 5 | 函式 Function
      • 【Returns】
      • 【Visibility】
      • 【stateMutability】
      • 【Constructor】
      • 【Function Overloading】
      • 【Fallback】
      • 【Useful Function】
      • 【Practice】
      • 【Answer】
    • | Chapter 6 | 資料結構 Data Structures
      • 【Array】
      • 【Mapping】
      • 【Structs】
      • 【Enum】
      • 【Practice】
      • 【Answer】
    • | Chapter 7 | 角色和全局訊息 Global Variables
      • 【Msg】
      • 【Block】
      • 【ABI】
      • 【TX】
      • 【Practice】
      • 【Answer】
  • Part II Medium
    • | Chapter 8 | 記憶體配置 Memory Allocation
    • | Chapter 9 | 異常處理 Handling Exception
      • 【Require】
      • 【Assert】
      • 【Revert】
      • 【Try/Catch】
      • 【Practice】
      • 【Answer】
    • | Chapter 10 | 事件 Event
      • 【emit】
      • 【Indexed】
      • 【web3.eth.subscribe()】
      • 【Logs with Data & Topics】
      • 【anonymous】
      • 【Practice】
      • 【Answer】
    • | Chapter 11 | 繼承 Inheritance
      • 【Inheritance】
      • 【Modifier】
      • 【合約互動】
      • 【Function Overriding】
      • 【Polymorphism】
      • 【多重繼承與 super】
      • 【Practice】
      • 【Answer】
    • | Chapter 12 | 介面 Interface
    • | Chapter 13 | 引用 Imports & 函式庫 Libraries
      • 【Library】
      • 【Import】
      • 【OpenZeppelin】
      • 【Practice】
      • 【Answer】
    • | Chapter 14 | ERC & Token
  • PART III Advanced
    • | Chapter 15 | 佈署 Deploy & 編譯 Compiler
    • | Chapter 16 | 開發工具 Dev. Tools
    • | Chapter 17 | 最佳化合約 Contract Optimization
  • | OTHERS | Information & Reference
    • 【結語】
    • 【參考資料】
Powered by GitBook
On this page

Was this helpful?

  1. Part I Basic
  2. | Chapter 7 | 角色和全局訊息 Global Variables

【Block】

Previous【Msg】Next【ABI】

Last updated 3 years ago

Was this helpful?

block 顧名思義就是區塊鏈的訊息,可以藉由調用下列函數來知道一些資訊。

  • block.basefee (uint): 當前區塊的基本費用 ( and )

  • block.chainid (uint): 當前的 chain id

  • block.coinbase (address payable): 當前區塊礦工地址

  • block.difficulty (uint): 當前區塊難度

  • block.gaslimit (uint): 當前區塊的 gas limit

  • block.number (uint): 當前區塊編號

  • block.timestamp (uint): 當前區塊的 timestamp,使用 UNIX 時間秒

官方強烈建議不要依賴 block.timestamp 來做為隨機數的種子,除非我們真的知道他要用來做什麼。

block.timestamp 可以被礦工有意無意的影響,壞礦工可能會使用特定的散列上運行賭場支付函數(casino payout function on a chosen hash),並進入不同的 hash 值當他們沒有獲得任何金錢報酬。

當前的 block.timestamp 必須「嚴格大於」前一個區塊,但唯一的保證是這個區塊會在兩個執行區塊的 timestamps 之間。不一定代表正確的時間,只是兩者之間的某處。

在 version 0.7.0, now 被移除了,現在我們必須只能使用 block.timestamp

注意謹慎使用 block.timestamp 和 blockhash,因爲他們都是有可能被篡改的。

EIP-3198
EIP-1559