πŸ“š
Open Polkadot Bootcamp
  • πŸ“š About the Bootcamp
    • πŸ“– Additional Resources
    • πŸ‘ Ask For Support
  • πŸ“– Curriculum
  • πŸ“•Rust Programming Language
    • Basic Rust
      • Introduction to Rust
        • πŸ§‘β€πŸ’» Excercises
      • Common Programming Concepts
        • πŸ§‘β€πŸ’» Excercises
      • Program Life Cycle
        • πŸ§‘β€πŸ’» Excercises
      • Ownership & Borrow Checker
      • Common Data Structures
    • Advanced Rust
      • Generic types, Trait extension and Advanced types
      • Lifetime Notation
      • Smart pointers & Macros
      • Common design patterns in Rust
      • Package management & How to structure your Rust project
      • Overview of the Rust ecosystem
  • πŸ“˜Building a blockchain with Polkadot SDK
    • Polkadot
      • Additional Reads
        • Why do you want to build a blockchain on Polkadot?
        • Understanding the sharded network design of Polkadot
      • Development on Polkadot
    • Polkadot SDK
      • Substrate
        • Create a new blockchain
          • πŸ§‘β€πŸ’» Exercise: Clone the minimal template
          • Understanding the architecture
          • Break down the node architecture
          • Introducing to Pop CLI tool
        • Adding a custom logic to runtime
          • πŸ§‘β€πŸ’» Exercise: Rust State Machine
          • Components of a Pallet
          • Hooks
          • Weights & Benchmarking
          • Extensions
            • Signed Extensions
            • Transaction Extensions
        • Common runtime modules
          • πŸ“•Example: System Pallet
          • πŸ“•Example: Contracts Pallet
          • πŸ“•Example: Assets Pallet
          • πŸ“•Example: Utility Pallet
        • Runtime API and RPC
        • Runtime upgrade
        • Bump Polkadot SDK versions
      • Cumulus
        • Introduction to Cumulus
          • Parachain from scratch
          • πŸ§‘β€πŸ’» Exercise: Build a parachain from scratch
        • Running a local relaychain network
          • Register & reserve a parachain
          • Launch the network & run a collator node
          • Launch the network with Pop CLI
        • Agile Coretime
    • Polkadot Hub
  • πŸ“’Smart Contract Development
    • Introduction
      • Introduction to PolkaVM
      • Getting started with Solidity development
      • Solidity File Structure
      • Contract Structure
    • Basic Solidity
      • Value types
      • Reference Types
      • Mapping Types
      • Simple Storage
    • Advanced Solidity
      • Units
      • Global Variables
      • Expression and Control Structures
      • Advanced Storage
      • Contract Tests
      • Contracts
Powered by GitBook
On this page
  • Block and Transaction Properties
  • Error handling
  • Members of Address Types
  • Contract-related keywords
  1. Smart Contract Development
  2. Advanced Solidity

Global Variables

Block and Transaction Properties

  • blockhash(uint blockNumber) returns (bytes32): hash of the given block when blocknumber is one of the 256 most recent blocks; otherwise returns zero

  • block.basefee (uint): current block’s base fee

  • block.chainid (uint): current chain id

  • block.coinbase (address payable): current block miner’s address

  • block.gaslimit (uint): current block gaslimit

  • block.number (uint): current block number

  • block.timestamp (uint): current block timestamp as seconds since unix epoch

  • gasleft() returns (uint256): remaining gas

  • msg.data (bytes calldata): complete calldata

  • msg.sender (address): sender of the message (current call)

  • msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier)

  • msg.value (uint): number of wei sent with the message

  • tx.gasprice (uint): gas price of the transaction

  • tx.origin (address): sender of the transaction (full call chain)

Error handling

  • assert(bool condition): causes a Panic error and thus state change reversion if the condition is not met - to be used for internal errors.

  • require(bool condition): reverts if the condition is not met - to be used for errors in inputs or external components.

  • require(bool condition, string memory message): reverts if the condition is not met - to be used for errors in inputs or external components. Also provides an error message.

  • revert(): abort execution and revert state changes

  • revert(string memory reason): abort execution and revert state changes, providing an explanatory string

Members of Address Types

  • <address>.balance (uint256): balance of the Address in Wei

  • <address>.code (bytes memory): code at the Address (can be empty)

  • <address>.codehash (bytes32): the codehash of the Address

  • <address payable>.transfer(uint256 amount): send given amount of Wei to Address, reverts on failure, forwards 2300 gas stipend, not adjustable

  • <address payable>.send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure, forwards 2300 gas stipend, not adjustable

  • <address>.call(bytes memory) returns (bool, bytes memory): issue low-level CALL with the given payload, returns success condition and return data, forwards all available gas, adjustable

  • <address>.delegatecall(bytes memory) returns (bool, bytes memory): issue low-level DELEGATECALL with the given payload, returns success condition and return data, forwards all available gas, adjustable

  • <address>.staticcall(bytes memory) returns (bool, bytes memory): issue low-level STATICCALL with the given payload, returns success condition and return data, forwards all available gas, adjustable

Contract-related keywords

  • this: The current contract, explicitly convertible to Address

  • super: A contract one level higher in the inheritance hierarchy

  • selfdestruct(address payable recipient): Destroy the current contract, sending its funds to the given Address and end execution. Note that selfdestruct has some peculiarities inherited from the EVM:

    • the receiving contract’s receive function is not executed.

    • the contract is only really destroyed at the end of the transaction and revert s might β€œundo” the destruction.

PreviousUnitsNextExpression and Control Structures

Last updated 5 months ago

πŸ“’