//SPDX-License-Identifier:MIT pragma solidity ^0.8.17; contract stateV { uint public num; function get() public view returns(uint){ return num; } function set(uint n) public { num = n; } }
gas 与 gas limit
1 2 3 4 5 6 7 8 9 10 11 12 13 14
pragma solidity ^0.8.17; //SPDX-License-Identifier: MIT contract gasAbout { int public i = 0; // 花光准备的gas会导致交易失败 // 状态改变会回退 // gas不会退款 function g() public { //循环到花光所限制的gas,交易失败,i不会发生改变 while(true) { ++i; } } }
pragma solidity ^0.8.17; //SPDX-License-Identifier: UNLICENSED contract Array { uint[] public arr ; uint[] public arr2 = [1, 2, 3]; uint[10] public arr3; function get(uint i) public view returns (uint){ return arr[i]; } function getArr() public view returns (uint[] memory) { return arr; } function push(uint i) public { arr.push(i); } function pop()public { //pop会相应减少长度 arr.pop(); } function getLength() public view returns(uint){ return arr.length; } function remove(uint index) public { //delete只删除相应索引上的值 delete arr[index]; } function examples() external { uint[] memory a = new uint[](5);//只能生成固定长度 } }