Solidity-Learning

Solidity 学习笔记

View the Project on GitHub XdpCs/Solidity-Learning

005-常量

背景

通过学习Solidity,然后输出文章检验自己的学习成果Github仓库

欢迎大家关注我的X

基础知识

例子

例子

该例子是常量的使用方法的例子

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

contract Constants {
    address public constant MY_ADDRESS = 0x0000000000000000000000000000000000001118;
    uint public constant MY_UINT = 1118;
    string public constant MY_STRING = "0x1118";
    bytes public constant MY_BYTES = "FYY";
    bool public constant MY_BOOL = false;
    bytes32 public constant MY_KE256 = keccak256(abi.encodePacked("100"));
}

程序解析

address public constant MY_ADDRESS = 0x0000000000000000000000000000000000001118;
uint public constant MY_UINT = 1118;
string public constant MY_STRING = "0x1118";
bytes public constant MY_BYTES = "FYY";
bool public constant MY_BOOL = false;
bytes32 public constant MY_KE256 = keccak256(abi.encodePacked("100"));

链接