typestar

Value types in Solidity

Sized integers, address, bool, bytes32: the primitives.

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

// Sized integers, address, bool, bytes32: the value types.
contract PlotRecord {
    uint256 public trees = 48;
    int16 public frostMarginC = -3;
    address public keeper = address(0);
    bool public irrigated = true;
    bytes32 public plotId = keccak256("north-slope");

    function double() external view returns (uint256) {
        return trees * 2;
    }
}

How it works

  1. uint256 and int16 size their storage exactly.
  2. address(0) is the zero address, the conventional empty.
  3. keccak256("...") fills a bytes32 fingerprint.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
389
Tokens
64
Three-star pace
60 tpm

At the three-star pace of 60 tokens a minute, this run takes about 64 seconds.

Type this snippet

Step 2 of 4 in Contracts, step 2 of 28 in Language basics.

← Previous Next →