Solidity 学习笔记
通过学习Solidity,然后输出文章检验自己的学习成果Github仓库
欢迎大家关注我的X
ether ?
gas消耗(gas spent) * gas价格(gas price)数量的ether
gas总数gas单价更高的gas价格的交易会有更高的优先权被打包入区块中gas将会被归还gasgasgas,这会导致交易失败,状态变量的更改会被回滚,消耗的gas不会被退还gas去滥用系统该例子说明了死循环,消耗完用户所提供的所有gas,导致交易失败
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract GasAndGasPrice {
uint public i = 0;
function forever() external {
while (true) {
i += 1;
}
}
}
function forever() external {
while (true) {
i += 1;
}
}
gas消耗光,然后交易失败