Verified contractExactMIT
MinGasRequirement
Address0x5109dbc06110ed408297d01dfebcd69f0bca4d85
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.31
- Same code
Only this contract
Details
- Compiler
- solc 0.8.31+commit.fd3a2265
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,224,253
- Creation transaction
- 0xf4b7d3359c…f85c7dc384
1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract MinGasRequirement {
// 定义最小 Gas 阈值
uint256 public constant GAS_THRESHOLD = 30000;
event GasCheckPassed(uint256 gasLeft);
/**
* @dev 这个函数要求调用时剩余 Gas 必须大于 30,000
* 注意:这里检查的是“到达该行代码时”剩余的 Gas
*/
function mustHaveHighGas() external {
uint256 remainingGas = gasleft();
// 核心逻辑:如果剩余 Gas <= 30000,则报错并回滚
require(remainingGas > GAS_THRESHOLD, "Gas insufficient: needs > 30000");
// 如果通过检查,触发一个事件证明成功
emit GasCheckPassed(remainingGas);
// 这里可以放置其他的业务逻辑...
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.