Skip to content

Commit 3fb9ccd

Browse files
Update docs
1 parent 886ca6d commit 3fb9ccd

12 files changed

+79
-35
lines changed

docs/assembly.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ of Solidity, you can use a special comment to annotate an assembly block as memo
381381
...
382382
}
383383
384-
Note that we will disallow the annotation via comment in a future breaking release; so, if you are not concerned with
385-
backward-compatibility with older compiler versions, prefer using the dialect string.
384+
.. warning::
385+
The ``memory-safe-assembly`` special comment will be deprecated in the next breaking version (0.9).
386+
So, if you are not concerned with backward-compatibility with older compiler versions, prefer using the dialect string.
386387

387388
Advanced Safe Use of Memory
388389
---------------------------

docs/common-patterns.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ you receive the funds of the person who is now the richest.
5757
// Remember to zero the pending refund before
5858
// sending to prevent reentrancy attacks
5959
pendingWithdrawals[msg.sender] = 0;
60-
payable(msg.sender).transfer(amount);
60+
(bool success, ) = payable(msg.sender).call{value: amount}("");
61+
require(success);
6162
}
6263
}
6364
@@ -84,7 +85,8 @@ This is as opposed to the more intuitive sending pattern:
8485
function becomeRichest() public payable {
8586
if (msg.value <= mostSent) revert NotEnoughEther();
8687
// This line can cause problems (explained below).
87-
richest.transfer(msg.value);
88+
(bool success, ) = richest.call{value: msg.value}("");
89+
require(success);
8890
richest = payable(msg.sender);
8991
mostSent = msg.value;
9092
}
@@ -210,8 +212,10 @@ restrictions highly readable.
210212
revert NotEnoughEther();
211213
212214
_;
213-
if (msg.value > amount)
214-
payable(msg.sender).transfer(msg.value - amount);
215+
if (msg.value > amount) {
216+
(bool success, ) = payable(msg.sender).call{value: msg.value - amount}("");
217+
require(success);
218+
}
215219
}
216220
217221
function forceOwnerChange(address newOwner)

docs/contracts/functions.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ will consume more gas than the 2300 gas stipend:
319319
not recommended, since the fallback is invoked and would not fail for interface confusions
320320
on the part of the sender).
321321

322+
.. warning::
323+
Note that ``send`` and ``transfer`` are scheduled to be deprecated in the next breaking version (0.9).
324+
You are encouraged to use the function ``call`` with and optional desired amount of gas and
325+
an empty parameter, e.g, ``call{value: amount}("")``.
326+
322327

323328
.. warning::
324329
A contract without a receive Ether function can receive Ether as a
@@ -440,6 +445,7 @@ operations as long as there is enough gas passed on to it.
440445
441446
// If someone sends Ether to that contract,
442447
// the transfer will fail, i.e. this returns false here.
448+
// This will report a warning (deprecation)
443449
return testPayable.send(2 ether);
444450
}
445451

docs/contracts/inheritance.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ of the variable:
377377

378378
.. _modifier-overriding:
379379

380-
Modifier Overriding
381-
===================
380+
Modifier Overriding (deprecated)
381+
================================
382382

383383
Function modifiers can override each other. This works in the same way as
384384
:ref:`function overriding <function-overriding>` (except that there is no overloading for modifiers). The
@@ -392,6 +392,7 @@ and the ``override`` keyword must be used in the overriding modifier:
392392
393393
contract Base
394394
{
395+
// This will report a warning (deprecation)
395396
modifier foo() virtual {_;}
396397
}
397398
@@ -411,11 +412,13 @@ explicitly:
411412
412413
contract Base1
413414
{
415+
// This will report a warning (deprecation)
414416
modifier foo() virtual {_;}
415417
}
416418
417419
contract Base2
418420
{
421+
// This will report a warning (deprecation)
419422
modifier foo() virtual {_;}
420423
}
421424
@@ -424,6 +427,8 @@ explicitly:
424427
modifier foo() override(Base1, Base2) {_;}
425428
}
426429
430+
.. warning::
431+
``virtual`` modifiers are deprecated and scheduled for removal in the next breaking version (0.9).
427432

428433

429434
.. index:: ! constructor

docs/control-structures.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,19 @@ and ``assert`` for internal error checking.
692692
:force:
693693
694694
// SPDX-License-Identifier: GPL-3.0
695-
pragma solidity >=0.5.0 <0.9.0;
695+
pragma solidity >=0.6.2 <0.9.0;
696696
697697
contract Sharer {
698698
function sendHalf(address payable addr) public payable returns (uint balance) {
699699
require(msg.value % 2 == 0, "Even value required.");
700700
uint balanceBeforeTransfer = address(this).balance;
701-
addr.transfer(msg.value / 2);
702-
// Since transfer throws an exception on failure and
703-
// cannot call back here, there should be no way for us to
704-
// still have half of the Ether.
705-
assert(address(this).balance == balanceBeforeTransfer - msg.value / 2);
701+
(bool success, ) = addr.call{value: msg.value / 2}("");
702+
// call returns false on failure, so either success is false
703+
// or the balance still is half of the Ether.
704+
assert(
705+
!success ||
706+
address(this).balance == balanceBeforeTransfer - msg.value / 2
707+
);
706708
return address(this).balance;
707709
}
708710
}
@@ -775,7 +777,8 @@ together with ``revert`` and the equivalent ``require``:
775777
if (msg.sender != owner)
776778
revert Unauthorized();
777779
778-
payable(msg.sender).transfer(address(this).balance);
780+
(bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
781+
require(success);
779782
}
780783
}
781784
@@ -914,4 +917,4 @@ in scope in the block that follows.
914917
out-of-gas situation and not a deliberate error condition:
915918
The caller always retains at least 1/64th of the gas in a call and thus
916919
even if the called contract goes out of gas, the caller still
917-
has some gas left.
920+
has some gas left.

docs/examples/blind-auction.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ to receive their Ether - contracts cannot activate themselves.
123123
124124
// msg.sender is not of type `address payable` and must be
125125
// explicitly converted using `payable(msg.sender)` in order
126-
// use the member function `send()`.
127-
if (!payable(msg.sender).send(amount)) {
126+
// use the member function `call()`.
127+
(bool success, ) = payable(msg.sender).call{value: amount}("");
128+
if (!success) {
128129
// No need to call throw here, just reset the amount owing
129130
pendingReturns[msg.sender] = amount;
130131
return false;
@@ -160,7 +161,8 @@ to receive their Ether - contracts cannot activate themselves.
160161
emit AuctionEnded(highestBidder, highestBid);
161162
162163
// 3. Interaction
163-
beneficiary.transfer(highestBid);
164+
(bool success, ) = beneficiary.call{value: highestBid}("");
165+
require(success);
164166
}
165167
}
166168
@@ -310,7 +312,8 @@ invalid bids.
310312
// the same deposit.
311313
bidToCheck.blindedBid = bytes32(0);
312314
}
313-
payable(msg.sender).transfer(refund);
315+
(bool success, ) = payable(msg.sender).call{value: refund}("");
316+
require(success);
314317
}
315318
316319
/// Withdraw a bid that was overbid.
@@ -323,7 +326,8 @@ invalid bids.
323326
// conditions -> effects -> interaction).
324327
pendingReturns[msg.sender] = 0;
325328
326-
payable(msg.sender).transfer(amount);
329+
(bool success, ) = payable(msg.sender).call{value: amount}("");
330+
require(success);
327331
}
328332
}
329333
@@ -336,7 +340,8 @@ invalid bids.
336340
if (ended) revert AuctionEndAlreadyCalled();
337341
emit AuctionEnded(highestBidder, highestBid);
338342
ended = true;
339-
beneficiary.transfer(highestBid);
343+
(bool success, ) = beneficiary.call{value: highestBid}("");
344+
require(success);
340345
}
341346
342347
// This is an "internal" function which means that it

docs/examples/micropayment.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ The full contract
185185
// this recreates the message that was signed on the client
186186
bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));
187187
require(recoverSigner(message, signature) == owner);
188-
payable(msg.sender).transfer(amount);
188+
(bool success, ) = payable(msg.sender).call{value: amount}("");
189+
require(success);
189190
}
190191
191192
/// freeze the contract and reclaim the leftover funds.
@@ -195,7 +196,8 @@ The full contract
195196
{
196197
require(msg.sender == owner);
197198
freeze();
198-
payable(msg.sender).transfer(address(this).balance);
199+
(bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
200+
require(success);
199201
}
200202
201203
/// signature methods.
@@ -406,9 +408,11 @@ The full contract
406408
require(msg.sender == recipient);
407409
require(isValidSignature(amount, signature));
408410
409-
recipient.transfer(amount);
411+
(bool success, ) = recipient.call{value: amount}("");
412+
require(success);
410413
freeze();
411-
sender.transfer(address(this).balance);
414+
(success, ) = sender.call{value: address(this).balance}("");
415+
require(success);
412416
}
413417
414418
/// the sender can extend the expiration at any time
@@ -430,7 +434,8 @@ The full contract
430434
{
431435
require(block.timestamp >= expiration);
432436
freeze();
433-
sender.transfer(address(this).balance);
437+
(bool success, ) = sender.call{value: address(this).balance}("");
438+
require(success);
434439
}
435440
436441
function isValidSignature(uint256 amount, bytes memory signature)

docs/examples/safe-remote.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ you can use state machine-like constructs inside a contract.
9797
// reentrancy-safe, because it is the
9898
// last call in this function and we
9999
// already changed the state.
100-
seller.transfer(address(this).balance);
100+
(bool success, ) = seller.call{value: address(this).balance}("");
101+
require(success);
101102
}
102103
103104
/// Confirm the purchase as buyer.
@@ -128,7 +129,8 @@ you can use state machine-like constructs inside a contract.
128129
// can call in again here.
129130
state = State.Release;
130131
131-
buyer.transfer(value);
132+
(bool success, ) = buyer.call{value: value}("");
133+
require(success);
132134
}
133135
134136
/// This function refunds the seller, i.e.
@@ -144,6 +146,7 @@ you can use state machine-like constructs inside a contract.
144146
// can call in again here.
145147
state = State.Inactive;
146148
147-
seller.transfer(3 * value);
149+
(bool success, ) = seller.call{value: 3 * value}("");
150+
require(success);
148151
}
149152
}

docs/layout-of-source-files.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ select between the two implementations of the ABI encoder and decoder.
103103
The new ABI coder (v2) is able to encode and decode arbitrarily nested
104104
arrays and structs. Apart from supporting more types, it involves more extensive
105105
validation and safety checks, which may result in higher gas costs, but also heightened
106-
security. It is considered
107-
non-experimental as of Solidity 0.6.0 and it is enabled by default starting
106+
security.
107+
It is considered non-experimental as of Solidity 0.6.0 and it is enabled by default starting
108108
with Solidity 0.8.0. The old ABI coder can still be selected using ``pragma abicoder v1;``.
109109

110+
.. warning::
111+
The ABI coder v1 is deprecated and scheduled for removal in the next breaking version (0.9).
112+
110113
The set of types supported by the new encoder is a strict superset of
111114
the ones supported by the old one. Contracts that use it can interact with ones
112115
that do not without limitations. The reverse is possible only as long as the

docs/security-considerations.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ To give an example, the following code contains a bug (it is just a snippet and
6565
mapping(address => uint) shares;
6666
/// Withdraw your share.
6767
function withdraw() public {
68+
// This will report a warning (deprecation)
6869
if (payable(msg.sender).send(shares[msg.sender]))
6970
shares[msg.sender] = 0;
7071
}
@@ -109,6 +110,7 @@ To avoid reentrancy, you can use the Checks-Effects-Interactions pattern as demo
109110
function withdraw() public {
110111
uint share = shares[msg.sender];
111112
shares[msg.sender] = 0;
113+
// This will report a warning (deprecation)
112114
payable(msg.sender).transfer(share);
113115
}
114116
}
@@ -255,6 +257,7 @@ Let's say you have a wallet contract like this:
255257
function transferTo(address payable dest, uint amount) public {
256258
// THE BUG IS RIGHT HERE, you must use msg.sender instead of tx.origin
257259
require(tx.origin == owner);
260+
// This will report a warning (deprecation)
258261
dest.transfer(amount);
259262
}
260263
}

0 commit comments

Comments
 (0)