Address
Collection of functions related to the address type.
isContract
Returns true if account
is a contract.
IMPORTANT
It is unsafe to assume that an address for which this function returns false is an externally owned account (EOA) and not a contract.
Among others, isContract
will return false for the following types of addresses:
an externally-owned account
a contract in construction
an address where a contract will be created
an address where a contract lived, but was destroyed
Furthermore, isContract
will also return true if the target contract within the same transaction is already scheduled for destruction by SELFDESTRUCT
, which only has an effect at the end of a transaction.
IMPORTANT
You shouldn't rely on isContract
to protect against flash loan attacks!
Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract constructor.
sendValue
Replacement for Solidity's transfer
: sends amount
wei to recipient
, forwarding all available gas, and reverting on errors.
EIP1884 increases the gas cost of certain opcodes, possibly making contracts go over the 2300 gas limit imposed by transfer
, making them unable to receive funds via transfer
. {sendValue} removes this limitation.
IMPORTANT
because control is transferred to recipient
, care must be taken to not create reentrancy vulnerabilities. Consider using {ReentrancyGuard} or the checks-effects-interactions pattern.
functionCall
Performs a Solidity function call using a low-level call
. A plain call
is an unsafe replacement for a function call: use this function instead.
If target
reverts with a revert reason, it is bubbled up by this function (like regular Solidity function calls).
Returns the raw returned data. To convert to the expected return value, use abi.decode
.
Requirements:
target
must be a contract.calling
target
withdata
must not revert.
Available since v3.1.
functionCall
Same as {xref-Address-functionCall-address-bytes-}[functionCall
], but with errorMessage
as a fallback revert reason when target
reverts.
Available since v3.1.
functionCallWithValue
Same as {xref-Address-functionCall-address-bytes-}[functionCall
], but also transferring value
wei to target
.
Requirements:
the calling contract must have an ETH balance of at least
value
.the called Solidity function must be
payable
.
Available since v3.1.
functionCallWithValue
Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[functionCallWithValue
], but with errorMessage
as a fallback revert reason when target
reverts.
Available since v3.1.
functionStaticCall
Same as {xref-Address-functionCall-address-bytes-}[functionCall
], but performing a static call.
Available since v3.3.
functionStaticCall
Same as {xref-Address-functionCall-address-bytes-string-}[functionCall
], but performing a static call.
Available since v3.3.
functionDelegateCall
Same as {xref-Address-functionCall-address-bytes-}[functionCall
], but performing a delegate call.
Available since v3.4.
functionDelegateCall
Same as {xref-Address-functionCall-address-bytes-string-}[functionCall
], but performing a delegate call.
Available since v3.4.
verifyCallResultFromTarget
Tool to verify that a low-level call to smart-contract was successful, and revert (either by bubbling the revert reason or using the provided one) in case of an unsuccessful call or if the target was not a contract.
Available since v4.8.
verifyCallResult
Tool to verify that a low-level call was successful, and revert if it wasn't, either by bubbling the revert reason or using the provided one.
Available since v4.3.
Address Summarize
The Address
smart contract in question is a library of functions related to the address type.
This library provides a set of tools for interacting with the other addresses and contracts safely and flexibly.
Address Check: The function
isContract(address account)
checks if the provided address is a contract. It returnstrue
if the address is a contract, andfalse
otherwise. This function is used to determine if an address is a contract or an externally-owned account (EOA).Value Transfer: The function
sendValue(address payable recipient, uint256 amount)
sends a specified amount of wei to a recipient address. It checks if the contract has enough balance to send the value, and if the recipient can receive the value.Low-Level Calls: The library provides several functions for making low-level calls to other contracts. These include
functionCall
,functionCallWithValue
,functionStaticCall
, andfunctionDelegateCall
. These functions allow the contract to interact with other contracts in a more flexible and customizable way than the standard Solidity function call syntax.Call Result Verification: The function
verifyCallResultFromTarget(address target, bool success, bytes memory returndata, string memory errorMessage)
checks the result of a low-level call to a target contract. If the call was successful, it checks if the target is a contract and returns the return data. If the call was not successful, it reverts with the provided error message.Error Handling: The function
_revert(bytes memory returndata, string memory errorMessage)
is used to handle errors. If the providedreturndata
is not empty, it bubbles up the revert reason from the target contract. If thereturndata
is empty, it reverts with the provided error message.
Last updated