Solidity – How to Alter the Gas Stipend with High-Level Delegate Call

delegatecallgassolidity

When using the DELEGATECALL opcode via assembly, we can pass a specific amount of gas:

let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

But the high-level DELEGATECALL does not have such argument:

(bool success, bytes memory returndata) = target.delegatecall(data);

How can we alter the gas stipend that we give to the delegated contract?

Best Answer

You can specify the gas using the gas modifier (in brackets) before the function args, e.g.:

(bool success, bytes memory returndata) = target.delegatecall{ gas: 10000 }(data);

The modifiers are documented here:

https://docs.soliditylang.org/en/v0.8.16/types.html#address

Related Topic