Solidity

記錄執行中特定點的氣體使用情況

  • August 2, 2021

如果這裡已經被問過,我很抱歉,但我目前正在建立一個限價訂單契約,我正在嘗試做類似的事情。

function fullfillMaxOrders() public {
while(gasConsumed <= gasLimit) {
   // do my stuff (which is running through a list of orders to process, each individual order may widely vary in gas usage (different tokens to transfer, different contracts to interact with...)
   //record gas consumed up to this point and store it in gasConsumed
}
// rest of the function 

} 你知道怎麼做嗎?我說的當然是記錄到目前為止消耗的氣體

它被稱為

gasleft() returns (uint256): remaining gas

<https://docs.soliditylang.org/en/v0.8.6/units-and-global-variables.html>

引用自:https://ethereum.stackexchange.com/questions/106519