You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/types/value-types.rst
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,8 +244,8 @@ For a quick reference of all members of address, see :ref:`address_related`.
244
244
245
245
* ``balance`` and ``transfer``
246
246
247
-
It is possible to query the balance of an address using the property ``balance``
248
-
and to send Ether (in units of wei) to a payable address using the ``transfer`` function:
247
+
It is possible to query the balance of an address using the property ``balance``
248
+
and to send Ether (in units of wei) to a payable address using the ``transfer`` function:
249
249
250
250
.. code-block:: solidity
251
251
:force:
@@ -254,9 +254,9 @@ and to send Ether (in units of wei) to a payable address using the ``transfer``
254
254
address myAddress = address(this);
255
255
if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);
256
256
257
-
The ``transfer`` function fails if the balance of the current contract is not large enough
258
-
or if the Ether transfer is rejected by the receiving account. The ``transfer`` function
259
-
reverts on failure.
257
+
The ``transfer`` function fails if the balance of the current contract is not large enough
258
+
or if the Ether transfer is rejected by the receiving account. The ``transfer`` function
259
+
reverts on failure.
260
260
261
261
.. note::
262
262
If ``x`` is a contract address, its code (more specifically: its :ref:`receive-ether-function`, if present, or otherwise its :ref:`fallback-function`, if present) will be executed together with the ``transfer`` call (this is a feature of the EVM and cannot be prevented). If that execution runs out of gas or fails in any way, the Ether transfer will be reverted and the current contract will stop with an exception.
@@ -268,7 +268,7 @@ reverts on failure.
268
268
269
269
* ``send``
270
270
271
-
``send`` is the low-level counterpart of ``transfer``. If the execution fails, the current contract will not stop with an exception, but ``send`` will return ``false``.
271
+
``send`` is the low-level counterpart of ``transfer``. If the execution fails, the current contract will not stop with an exception, but ``send`` will return ``false``.
272
272
273
273
.. warning::
274
274
There are some dangers in using ``send``: The transfer fails if the call stack depth is at 1024
@@ -285,16 +285,16 @@ reverts on failure.
285
285
286
286
* ``call``, ``delegatecall`` and ``staticcall``
287
287
288
-
In order to interface with contracts that do not adhere to the ABI,
289
-
or to get more direct control over the encoding,
290
-
the functions ``call``, ``delegatecall`` and ``staticcall`` are provided.
291
-
They all take a single ``bytes memory`` parameter and
292
-
return the success condition (as a ``bool``) and the returned data
293
-
(``bytes memory``).
294
-
The functions ``abi.encode``, ``abi.encodePacked``, ``abi.encodeWithSelector``
295
-
and ``abi.encodeWithSignature`` can be used to encode structured data.
288
+
In order to interface with contracts that do not adhere to the ABI,
289
+
or to get more direct control over the encoding,
290
+
the functions ``call``, ``delegatecall`` and ``staticcall`` are provided.
291
+
They all take a single ``bytes memory`` parameter and
292
+
return the success condition (as a ``bool``) and the returned data
293
+
(``bytes memory``).
294
+
The functions ``abi.encode``, ``abi.encodePacked``, ``abi.encodeWithSelector``
295
+
and ``abi.encodeWithSignature`` can be used to encode structured data.
296
296
297
-
Example:
297
+
Example:
298
298
299
299
.. code-block:: solidity
300
300
@@ -315,35 +315,35 @@ Example:
315
315
arbitrary arguments and would also handle a first argument of type
316
316
``bytes4`` differently. These edge cases were removed in version 0.5.0.
317
317
318
-
It is possible to adjust the supplied gas with the ``gas`` modifier:
318
+
It is possible to adjust the supplied gas with the ``gas`` modifier:
In a similar way, the function ``delegatecall`` can be used: the difference is that only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract. The purpose of ``delegatecall`` is to use library code which is stored in another contract. The user has to ensure that the layout of storage in both contracts is suitable for delegatecall to be used.
336
+
In a similar way, the function ``delegatecall`` can be used: the difference is that only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract. The purpose of ``delegatecall`` is to use library code which is stored in another contract. The user has to ensure that the layout of storage in both contracts is suitable for delegatecall to be used.
337
337
338
338
.. note::
339
339
Prior to homestead, only a limited variant called ``callcode`` was available that did not provide access to the original ``msg.sender`` and ``msg.value`` values. This function was removed in version 0.5.0.
340
340
341
-
Since byzantium ``staticcall`` can be used as well. This is basically the same as ``call``, but will revert if the called function modifies the state in any way.
341
+
Since byzantium ``staticcall`` can be used as well. This is basically the same as ``call``, but will revert if the called function modifies the state in any way.
342
342
343
-
All three functions ``call``, ``delegatecall`` and ``staticcall`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
343
+
All three functions ``call``, ``delegatecall`` and ``staticcall`` are very low-level functions and should only be used as a *last resort* as they break the type-safety of Solidity.
344
344
345
-
The ``gas`` option is available on all three methods, while the ``value`` option is only available
346
-
on ``call``.
345
+
The ``gas`` option is available on all three methods, while the ``value`` option is only available
346
+
on ``call``.
347
347
348
348
.. note::
349
349
It is best to avoid relying on hardcoded gas values in your smart contract code,
@@ -352,9 +352,9 @@ on ``call``.
352
352
353
353
* ``code`` and ``codehash``
354
354
355
-
You can query the deployed code for any smart contract. Use ``.code`` to get the EVM bytecode as a
356
-
``bytes memory``, which might be empty. Use ``.codehash`` to get the Keccak-256 hash of that code
357
-
(as a ``bytes32``). Note that ``addr.codehash`` is cheaper than using ``keccak256(addr.code)``.
355
+
You can query the deployed code for any smart contract. Use ``.code`` to get the EVM bytecode as a
356
+
``bytes memory``, which might be empty. Use ``.codehash`` to get the Keccak-256 hash of that code
357
+
(as a ``bytes32``). Note that ``addr.codehash`` is cheaper than using ``keccak256(addr.code)``.
358
358
359
359
.. warning::
360
360
The output of ``addr.codehash`` may be ``0`` if the account associated with ``addr`` is empty or non-existent
0 commit comments