Migrate contracts to Solidity 0.7 (#2319)
* Update contract pragmas to solidity 0.7 * Remove internal declaration on constructors * Reference SafeMath explicitely * Remove public constructor declaration from abstract contracts * Remove public constructor declaration from non-abstract contracts
This commit is contained in:
@ -13,7 +13,7 @@ OpenZeppelin provides xref:api:access.adoc#Ownable[`Ownable`] for implementing o
|
||||
----
|
||||
// contracts/MyContract.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
@ -62,7 +62,7 @@ Here's a simple example of using `AccessControl` in an xref:tokens.adoc#ERC20[`E
|
||||
----
|
||||
// contracts/MyToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@ -71,7 +71,7 @@ contract MyToken is ERC20, AccessControl {
|
||||
// Create a new role identifier for the minter role
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
|
||||
constructor(address minter) public ERC20("MyToken", "TKN") {
|
||||
constructor(address minter) ERC20("MyToken", "TKN") {
|
||||
// Grant the minter role to a specified account
|
||||
_setupRole(MINTER_ROLE, minter);
|
||||
}
|
||||
@ -94,7 +94,7 @@ Let's augment our ERC20 token example by also defining a 'burner' role, which le
|
||||
----
|
||||
// contracts/MyToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@ -103,7 +103,7 @@ contract MyToken is ERC20, AccessControl {
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
|
||||
|
||||
constructor(address minter, address burner) public ERC20("MyToken", "TKN") {
|
||||
constructor(address minter, address burner) ERC20("MyToken", "TKN") {
|
||||
_setupRole(MINTER_ROLE, minter);
|
||||
_setupRole(BURNER_ROLE, burner);
|
||||
}
|
||||
@ -139,7 +139,7 @@ Let's take a look at the ERC20 token example, this time taking advantage of the
|
||||
----
|
||||
// contracts/MyToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@ -148,7 +148,7 @@ contract MyToken is ERC20, AccessControl {
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
|
||||
|
||||
constructor() public ERC20("MyToken", "TKN") {
|
||||
constructor() ERC20("MyToken", "TKN") {
|
||||
// Grant the contract deployer the default admin role: it will be able
|
||||
// to grant and revoke any roles
|
||||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
||||
|
||||
@ -34,7 +34,7 @@ Here's what a contract for tokenized items might look like:
|
||||
----
|
||||
// contracts/GameItems.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
|
||||
|
||||
@ -45,7 +45,7 @@ contract GameItems is ERC1155 {
|
||||
uint256 public constant SWORD = 3;
|
||||
uint256 public constant SHIELD = 4;
|
||||
|
||||
constructor() public ERC1155("https://game.example/api/item/{1}.json") {
|
||||
constructor() ERC1155("https://game.example/api/item/{1}.json") {
|
||||
_mint(msg.sender, GOLD, 10**18, "");
|
||||
_mint(msg.sender, SILVER, 10**27, "");
|
||||
_mint(msg.sender, THORS_HAMMER, 1, "");
|
||||
@ -132,7 +132,7 @@ In order for our contract to receive ERC1155 tokens we can inherit from the conv
|
||||
----
|
||||
// contracts/MyContract.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ Let's say we want a token with a fixed supply of 1000, initially allocated to th
|
||||
[source,solidity]
|
||||
----
|
||||
contract ERC20FixedSupply is ERC20 {
|
||||
constructor() public {
|
||||
constructor() {
|
||||
totalSupply += 1000;
|
||||
balances[msg.sender] += 1000;
|
||||
}
|
||||
@ -26,7 +26,7 @@ Starting with Contracts v2 this pattern is not only discouraged, but disallowed.
|
||||
[source,solidity]
|
||||
----
|
||||
contract ERC20FixedSupply is ERC20 {
|
||||
constructor() public ERC20("Fixed", "FIX") {
|
||||
constructor() ERC20("Fixed", "FIX") {
|
||||
_mint(msg.sender, 1000);
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ The mechanism we will implement is a token reward for the miners that produce Et
|
||||
[source,solidity]
|
||||
----
|
||||
contract ERC20WithMinerReward is ERC20 {
|
||||
constructor() public ERC20("Reward", "RWD") {}
|
||||
constructor() ERC20("Reward", "RWD") {}
|
||||
|
||||
function mintMinerReward() public {
|
||||
_mint(block.coinbase, 1000);
|
||||
@ -68,7 +68,7 @@ The accounts with the minter role don't need to be externally owned, though, and
|
||||
contract MinerRewardMinter {
|
||||
ERC20PresetMinterPauser _token;
|
||||
|
||||
constructor(ERC20PresetMinterPauser token) public {
|
||||
constructor(ERC20PresetMinterPauser token) {
|
||||
_token = token;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ Adding to the supply mechanism from previous sections, we can use this hook to m
|
||||
[source,solidity]
|
||||
----
|
||||
contract ERC20WithAutoMinerReward is ERC20 {
|
||||
constructor() public ERC20("Reward", "RWD") {}
|
||||
constructor() ERC20("Reward", "RWD") {}
|
||||
|
||||
function _mintMinerReward() internal {
|
||||
_mint(block.coinbase, 1000);
|
||||
|
||||
@ -15,12 +15,12 @@ Here's what our GLD token might look like.
|
||||
----
|
||||
// contracts/GLDToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract GLDToken is ERC20 {
|
||||
constructor(uint256 initialSupply) public ERC20("Gold", "GLD") {
|
||||
constructor(uint256 initialSupply) ERC20("Gold", "GLD") {
|
||||
_mint(msg.sender, initialSupply);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ Here's what a contract for tokenized items might look like:
|
||||
----
|
||||
// contracts/GameItem.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
||||
@ -23,7 +23,7 @@ contract GameItem is ERC721 {
|
||||
using Counters for Counters.Counter;
|
||||
Counters.Counter private _tokenIds;
|
||||
|
||||
constructor() public ERC721("GameItem", "ITM") {}
|
||||
constructor() ERC721("GameItem", "ITM") {}
|
||||
|
||||
function awardItem(address player, string memory tokenURI)
|
||||
public
|
||||
|
||||
@ -20,13 +20,12 @@ We will replicate the `GLD` example of the xref:erc20.adoc#constructing-an-erc20
|
||||
----
|
||||
// contracts/GLDToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
|
||||
|
||||
contract GLDToken is ERC777 {
|
||||
constructor(uint256 initialSupply, address[] memory defaultOperators)
|
||||
public
|
||||
ERC777("Gold", "GLD", defaultOperators)
|
||||
{
|
||||
_mint(msg.sender, initialSupply, "", "");
|
||||
|
||||
@ -20,7 +20,7 @@ For example, imagine you want to change xref:api:access.adoc#AccessControl[`Acce
|
||||
```solidity
|
||||
// contracts/ModifiedAccessControl.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
|
||||
@ -48,7 +48,7 @@ Here is a modified version of xref:api:access.adoc#AccessControl[`AccessControl`
|
||||
```solidity
|
||||
// contracts/ModifiedAccessControl.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
|
||||
@ -80,7 +80,7 @@ Hooks are simply functions that are called before or after some action takes pla
|
||||
Here's how you would implement the `IERC721Receiver` pattern in `ERC20`, using the xref:api:token/ERC20.adoc#ERC20-_beforeTokenTransfer-address-address-uint256-[`_beforeTokenTransfer`] hook:
|
||||
|
||||
```solidity
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ Instead of using `GSNRecipient` directly, your GSN recipient contract will inste
|
||||
import "@openzeppelin/contracts/GSN/GSNRecipientSignature.sol";
|
||||
|
||||
contract MyContract is GSNRecipientSignature {
|
||||
constructor(address trustedSigner) public GSNRecipientSignature(trustedSigner) {
|
||||
constructor(address trustedSigner) GSNRecipientSignature(trustedSigner) {
|
||||
}
|
||||
}
|
||||
----
|
||||
@ -108,7 +108,7 @@ Your GSN recipient contract needs to inherit from `GSNRecipientERC20Fee` along w
|
||||
----
|
||||
// contracts/MyContract.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/GSN/GSNRecipientERC20Fee.sol";
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
@ -116,7 +116,7 @@ import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
contract MyContract is GSNRecipientERC20Fee, AccessControl {
|
||||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
||||
|
||||
constructor() public GSNRecipientERC20Fee("FeeToken", "FEE") {
|
||||
constructor() GSNRecipientERC20Fee("FeeToken", "FEE") {
|
||||
_setupRole(MINTER_ROLE, _msgSender());
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ Once your strategy is ready, all your GSN recipient needs to do is inherit from
|
||||
[source,solidity]
|
||||
----
|
||||
contract MyContract is MyCustomGSNStrategy {
|
||||
constructor() public MyCustomGSNStrategy() {
|
||||
constructor() MyCustomGSNStrategy() {
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
@ -28,12 +28,12 @@ Once installed, you can use the contracts in the library by importing them:
|
||||
----
|
||||
// contracts/MyNFT.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
|
||||
contract MyNFT is ERC721 {
|
||||
constructor() ERC721("MyNFT", "MNFT") public {
|
||||
constructor() ERC721("MyNFT", "MNFT") {
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
Reference in New Issue
Block a user