Update contracts to support Solidity 0.8.x (#2442)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
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.8.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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@ -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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
@ -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.8.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.8.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/{id}.json") {
|
||||
constructor() ERC1155("https://game.example/api/item/{id}.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.8.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);
|
||||
@ -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,7 +15,7 @@ Here's what our GLD token might look like.
|
||||
----
|
||||
// contracts/GLDToken.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
||||
@ -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.8.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,7 +20,7 @@ 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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
|
||||
|
||||
|
||||
@ -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.8.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.8.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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
||||
@ -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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/GSN/GSNRecipientERC20Fee.sol";
|
||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
@ -116,11 +116,11 @@ 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());
|
||||
}
|
||||
|
||||
function _msgSender() internal view override(Context, GSNRecipient) returns (address payable) {
|
||||
function _msgSender() internal view override(Context, GSNRecipient) returns (address) {
|
||||
return GSNRecipient._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,7 +28,7 @@ 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.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user