کانال بله, جهت پشتیبانی و اطلاع رسانی کانال بله, جهت پشتیبانی و اطلاع رسانی
عضویت

متغیرهای ویژه در سالیدیتی

متغیرهای ویژه متغیرهایی هستند که در سطح Global در دسترس هستند و اطلاعاتی در مورد بلاک چین ارائه می دهند. در ادامه لیستی از متغیرهای Special آمده است:

Special Variable & Description
Sr.No.

blockhash(uint blockNumber) returns (bytes32)

Hash of the given block - only works for 256 most recent, excluding current, blocks.

1

block.coinbase (address payable)

Current block miner's address.

2

block.difficulty (uint)

current block difficulty.

3

block.gaslimit (uint)

Current block gaslimit.

4

block.number (uint)

Current block number.

5

block.timestamp

Current block timestamp as seconds since unix epoch.

6

gasleft() returns (uint256)

Remaining gas.

7

msg.data (bytes calldata)

Complete calldata.

8

msg.sender (address payable)

Sender of the message (current call).

9

msg.sig (bytes4)

First four bytes of the calldata (i.e. function identifier)

10

msg.value (uint)

Number of wei sent with the message.

11

now (uint)

Current block timestamp (alias for block.timestamp).

12

tx.gasprice (uint)

Gas price of the transaction.

13

tx.origin (address payable)

Sender of the transaction (full call chain).

14

مثال

کد زیر را امتحان نمایید تا استفاده از msg را مشاهده کنید.( یک متغیر خاص برای دریافت آدرس فرستنده در Solidity)

pragma solidity ^0.5.0;

contract LedgerBalance {
   mapping(address => uint) public balances;

   function updateBalance(uint newBalance) public {
      balances[msg.sender] = newBalance;
   }
}
contract Updater {
   function updateBalance() public returns (uint) {
      LedgerBalance ledgerBalance = new LedgerBalance();
      ledgerBalance.updateBalance(10);
      return ledgerBalance.balances(address(this));
   }
}
1402/01/14 619
رمز عبور : tahlildadeh.com یا www.tahlildadeh.com
نظرات شما

نظرات خود را ثبت کنید...