Programming Language/Solidity
Solidity - Gas
Yongari
2022. 12. 22. 22:09
How much ether do you need to pay for a transaction?
당신은 거래를 위해 얼마를 지불해야 합니까?
You pay gas spent * gas price amount of ether, where
당신은 다음과 같은 경우에 사용된 가스 * 이더(ETH) 의 가스 가격 금액을 지불합니다.
- gas is a unit of computation (가스는 계산의 단위이다.)
- gas spent is the total amount of gas used in a transaction (사용된 가스는 거래에서 사용된 가스의 총량이다.)
- gas price is how much ether you are willing to pay per gas (가스 가격은 당신이 가스 당 지불할 의향이 있는 이더(ETH)의 양이다.)
Transactions with higher gas price have higher priority to be included in a block.
(가스 가격이 높은 거래는 블록에 포함되는 것이 우선순위가 높다.)
Unspent gas will be refunded.
(사용하지 않은 가스는 환불됩니다.)
Gas Limit
가스 제한
There are 2 upper bounds to the amount of gas you can spend
당신이 쓸 수 있는 가스의 양에는 두 가지 상한이 있다.
- gas limit (max amount of gas you're willing to use for your transaction, set by you)
가스 한도(거래에 사용할 수 있는 최대 가스량, 사용자가 설정) - block gas limit (max amount of gas allowed in a block, set by the network)
블록 가스 한계(네트워크에 의해 설정된 블록에서 허용되는 최대 가스량)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Gas {
uint public i = 0;
// Using up all of the gas that you send causes your transaction to fail.
// State changes are undone.
// Gas spent are not refunded.
function forever() public {
// Here we run a loop until all of the gas are spent
// and the transaction fails
while (true) {
i += 1;
}
}
}