You can specify the value in the call
opcode but delegatecall
only lets you specify the gas.
-
1Perhaps you are referring to the low-level assembly opcodes. In plain Solidity, you can adjust both the gas and the value via the special options <addr>.delegatecall{value, gas}.– Paul Razvan BergCommented Sep 7, 2021 at 11:25
1 Answer
When you specify a value
, you are transferring ETH from the calling contract to the called contract. But delegatecall doesn't actually switch which contract is running, instead it loads the other contract's code and runs it as if it was the calling contract.
For example, if you call
Michael Jordan to dunk the basketball, it makes sense to pass him the basketball at the same time (msg.value
) so he can dunk it.
However, if you are delegatecall
loading Stephen Curry brain into yours so you yourself can make a three point shot from where you stand, then it's you're body that will be making the shot, and it makes no sense to first pass the ball to Stephen Curry.
-
That's a nice analogy but doesn't CALLCODE also do the same thing (loading in code in context of current address)? Yet with CALLCODE you can specify msg.value too Commented Jun 29, 2021 at 20:06
-
@DylanKerler No, CALLCODE is different from DELEGATECALL ethereum.stackexchange.com/questions/3667/….– Ismael ♦Commented Jul 6, 2021 at 3:23
-
@Ismael Of course it's different... It's a different opcode. I mean that CALLCODE does the same thing as DELEGATECALL in that it executes code in the context of the calling contract. So why does CALLCODE have the additional parameter? Commented Jul 8, 2021 at 9:55
-
3@DylanKerler An important difference is that CALLCODE changes msg.sender and DELEGATECALL doesn't. It makes sense to support transfers for CALLCODE since there's a sender and recipient.– Ismael ♦Commented Jul 8, 2021 at 14:02
-