My Image
CoursesQuizzesProblemsContestsSmartBooks
Contest!

No results found

LOGINREGISTER
My ProgressCoursesQuizzesProblemsContestsSmartbooks
Published on 31 Dec 2021
Solidity Global Variables
Use case and syntax of different solidity variables
img
Aniket Savji
0
Like
129

Global Variables

These are special variables which exist in global workspace and provide information about the blockchain and transaction properties.

Description :

  • block.coinbase (address payable)  -  Current block miner's address
  • block.difficulty (uint)  -   Current block difficulty
  • 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 payable)  -  Sender of the message (current caller)
  • msg.sig (bytes4)  -  First four bytes of the calldata (function identifier)
  • msg.value (uint)  -  Number of wei sent with the message
  • tx.gasprice (uint)    Gas price of the transaction
  • tx.origin (address payable)    Sender of the transaction

Code Example : 

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract g_variables {
  
   function block_info() public view returns(address payable, uint, uint, uint, uint){
      return (block.coinbase, block.difficulty, block.gaslimit, block.number, block.timestamp);
   }

   function msg_info() public payable returns(bytes calldata, address, bytes4, uint){
      return (msg.data, msg.sender, msg.sig, msg.value);
   }

   function tx_info() public view returns(uint, address, uint256){
      return (tx.gasprice, tx.origin, gasleft());
   }

}
Enjoyed the SmartBook?
Like
logo
contact@dapp-world.com
Katraj, Pune, Maharashtra, India - 411048

Follow Us

linkedintwitteryoutubediscordinstagram

Products

  • SmartBooks
  • Courses
  • Quizzes
  • Assessments

Support

  • Contact Us
  • FAQ
  • Privacy Policy
  • T&C

Backed By

ah! ventures

Copyright 2023 - All Rights Reserved.

Recommended from DAppWorld
img
1 May 2021
How to connect Ganache with Metamask and deploy Smart contracts on remix without
Set up your development environment with (Metamask + Ganache + Remix) and skip truffle :)
3 min read
11509
5
img
8 Jul 2021
How to interact with smart contarct from backend node js
call and send functions from backend server side using nodejs
3 min read
8103
2
img
18 Aug 2021
Send transaction with web3 using python
Introduction to web3.py and sending transaction on testnet
3 min read
6229
5
img
5 Aug 2021
Deploy Smart Contract on Polygon POS using Hardhat
how to deploy smart contracts on polygon pos chain using hardhat both mainnet and testnet ?
3 min read
5540
3