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
+60-60Lines changed: 60 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -247,39 +247,39 @@ For a quick reference of all members of address, see :ref:`address_related`.
247
247
It is possible to query the balance of an address using the property ``balance``
248
248
and to send Ether (in units of wei) to a payable address using the ``transfer`` function:
249
249
250
-
.. code-block:: solidity
251
-
:force:
250
+
.. code-block:: solidity
251
+
:force:
252
252
253
-
address payable x = payable(0x123);
254
-
address myAddress = address(this);
255
-
if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);
253
+
address payable x = payable(0x123);
254
+
address myAddress = address(this);
255
+
if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);
256
256
257
257
The ``transfer`` function fails if the balance of the current contract is not large enough
258
258
or if the Ether transfer is rejected by the receiving account. The ``transfer`` function
259
259
reverts on failure.
260
260
261
-
.. note::
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.
261
+
.. note::
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.
263
263
264
-
.. warning::
265
-
``transfer`` is deprecated and scheduled for removal in the next breaking version (0.9).
266
-
Use the :ref:`call function <address_call_functions>` with an optionally provided maximum amount of
267
-
gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``.
264
+
.. warning::
265
+
``transfer`` is deprecated and scheduled for removal in the next breaking version (0.9).
266
+
Use the :ref:`call function <address_call_functions>` with an optionally provided maximum amount of
267
+
gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``.
268
268
269
269
* ``send``
270
270
271
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
-
.. warning::
274
-
There are some dangers in using ``send``: The transfer fails if the call stack depth is at 1024
275
-
(this can always be forced by the caller) and it also fails if the recipient runs out of gas. So in order
276
-
to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better:
277
-
use a pattern where the recipient withdraws the Ether.
273
+
.. warning::
274
+
There are some dangers in using ``send``: The transfer fails if the call stack depth is at 1024
275
+
(this can always be forced by the caller) and it also fails if the recipient runs out of gas. So in order
276
+
to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better:
277
+
use a pattern where the recipient withdraws the Ether.
278
278
279
-
.. warning::
280
-
``send`` is deprecated and scheduled for removal in the next breaking version (0.9).
281
-
Use the :ref:`call function <address_call_functions>` with an optionally provided maximum amount of
282
-
gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``.
279
+
.. warning::
280
+
``send`` is deprecated and scheduled for removal in the next breaking version (0.9).
281
+
Use the :ref:`call function <address_call_functions>` with an optionally provided maximum amount of
282
+
gas (default forwards all remaining gas) and an empty calldata parameter, e.g., ``call{value: amount}("")``.
283
283
284
284
.. _address_call_functions:
285
285
@@ -296,76 +296,76 @@ For a quick reference of all members of address, see :ref:`address_related`.
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
-
.. note::
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.
338
+
.. note::
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
-
.. note::
349
-
It is best to avoid relying on hardcoded gas values in your smart contract code,
350
-
regardless of whether state is read from or written to, as this can have many pitfalls.
351
-
Also, access to gas might change in the future.
348
+
.. note::
349
+
It is best to avoid relying on hardcoded gas values in your smart contract code,
350
+
regardless of whether state is read from or written to, as this can have many pitfalls.
351
+
Also, access to gas might change in the future.
352
352
353
353
* ``code`` and ``codehash``
354
354
355
355
You can query the deployed code for any smart contract. Use ``.code`` to get the EVM bytecode as a
356
356
``bytes memory``, which might be empty. Use ``.codehash`` to get the Keccak-256 hash of that code
357
357
(as a ``bytes32``). Note that ``addr.codehash`` is cheaper than using ``keccak256(addr.code)``.
358
358
359
-
.. warning::
360
-
The output of ``addr.codehash`` may be ``0`` if the account associated with ``addr`` is empty or non-existent
361
-
(i.e., it has no code, zero balance, and zero nonce as defined by `EIP-161 <https://eips.ethereum.org/EIPS/eip-161>`_).
362
-
If the account has no code but a non-zero balance or nonce, then ``addr.codehash`` will output the Keccak-256 hash of empty data
363
-
(i.e., ``keccak256("")`` which is equal to ``c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470``), as defined by
0 commit comments