49 - External Calls
Call/Delegatecall/Staticcall: In order to interface with contracts that do not adhere to the ABI, or to get more direct control over the encoding, the functions call
, delegatecall
and staticcall
are provided.
They all take a single bytes
memory parameter and return the success condition (as a bool) and the returned data (bytes memory)
.
The functions abi.encode
, abi.encodePacked
, abi.encodeWithSelector
and abi.encodeWithSignature
can be used to encode structured data.
-
gas
andvalue
modifiers can be used with these functions (delegatecall
doesn’t supportvalue
) to specify the amount of gas and Ether value passed to the callee. -
With
delegatecall
, only the code of the given address is used but all other aspects (storage, balance,msg.sender
etc.) are taken from the current contract. The purpose ofdelegatecall
is to use library/logic code which is stored in callee contract but operate on the state of the caller contract -
With
staticcall
, the execution will revert if the called function modifies the state in any way
- call, delegatecall, staticcall
- Parameters:
bytes memory
- Return:
success, bytes memory
abi.\*
-> Functions, gas/valuedelegatecall
-> State/Modifystaticcall
-> State/Use- Security: Low-level Call, Untrusted Contract, Reentrancy, Return Value Check