Gas and Execution Issues
Insufficient GAS at Runtime
error: execution failed: insufficient GASCause: The transaction's system fee doesn't cover the execution cost.
Diagnosis:
Check gas consumption with
gasleft():solidityfunction expensiveOperation() external { uint256 gasBefore = gasleft(); // ... operation ... uint256 gasUsed = gasBefore - gasleft(); Runtime.log(string(abi.encodePacked("Gas used: ", gasUsed))); }Use the
withGasLimitmodifier fromFrameworkBase:solidityfunction criticalOp() external withGasLimit(50000000) { // Reverts early if < 0.5 GAS remaining }
Common gas-heavy operations:
| Operation | Approximate Cost |
|---|---|
System.Storage.Put (new key) | 200,000+ GAS units |
System.Storage.Put (update) | 100,000+ GAS units |
System.Contract.Call | 32,768 GAS units |
CryptoLib.verifyWithECDsa | 1,000,000+ GAS units |
| Large array iteration | Scales with array size |
WARNING
Neo GAS uses 10^8 decimals (not 10^18 like Ethereum). 1 GAS = 100,000,000 fractional units. Adjust your constants accordingly.
