mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prefer .transfer() over .send() in the documentation
This commit is contained in:
parent
c674155e58
commit
c46c68dfd8
@ -80,31 +80,31 @@ Operators:
|
||||
Members of Addresses
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* ``balance`` and ``send``
|
||||
* ``balance`` and ``transfer``
|
||||
|
||||
For a quick reference, see :ref:`address_related`.
|
||||
|
||||
It is possible to query the balance of an address using the property ``balance``
|
||||
and to send Ether (in units of wei) to an address using the ``send`` function:
|
||||
and to send Ether (in units of wei) to an address using the ``transfer`` function:
|
||||
|
||||
::
|
||||
|
||||
address x = 0x123;
|
||||
address myAddress = this;
|
||||
if (x.balance < 10 && myAddress.balance >= 10) x.send(10);
|
||||
if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);
|
||||
|
||||
.. note::
|
||||
If ``x`` is a contract address, its code (more specifically: its fallback function, if present) will be executed together with the ``send`` call (this is a limitation 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. In this case, ``send`` returns ``false``.
|
||||
If ``x`` is a contract address, its code (more specifically: its fallback function, if present) will be executed together with the ``transfer`` call (this is a limitation 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.
|
||||
|
||||
* ``send``
|
||||
|
||||
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``.
|
||||
|
||||
.. warning::
|
||||
There are some dangers in using ``send``: The transfer fails if the call stack depth is at 1024
|
||||
(this can always be forced by the caller) and it also fails if the recipient runs out of gas. So in order
|
||||
to make safe Ether transfers, always check the return value of ``send`` or even better:
|
||||
Use a pattern where the recipient withdraws the money.
|
||||
|
||||
* ``transfer``
|
||||
|
||||
Transfer operates the same way as ``send``, with the exception that it will cause a exception if the transfer has failed.
|
||||
to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better:
|
||||
use a pattern where the recipient withdraws the money.
|
||||
|
||||
* ``call``, ``callcode`` and ``delegatecall``
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user