Solidity 学习笔记
通过学习Solidity
,然后输出文章检验自己的学习成果Github仓库
欢迎大家关注我的X
gas
成本,还可以提高合约安全性keccak256
、sha256
、ripemd160
、ecrecover
、addmod
和 mulmod
(尽管除了keccak256
之外,它们确实调用外部合约)string
和bytes
可以声明为constant
该例子是常量的使用方法的例子
// 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"));