三种token的demo
This commit is contained in:
9
README.md
Normal file
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# ERC 智能合约DEMO
|
||||
|
||||
### 编辑器地址
|
||||
|
||||
> https://remix.ethereum.org/
|
||||
|
||||
### 共享本地内容
|
||||
|
||||
> remixd -s /Users/jason/Documents/Develop/Sol-Projects/ERC-DEV -u https://remix.ethereum.org
|
||||
17
compiler_config.json
Normal file
17
compiler_config.json
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
{
|
||||
"language": "Solidity",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"": ["ast"],
|
||||
"*": ["abi", "metadata", "devdoc", "userdoc", "storageLayout", "evm.legacyAssembly", "evm.bytecode", "evm.deployedBytecode", "evm.methodIdentifiers", "evm.gasEstimates", "evm.assembly"]
|
||||
}
|
||||
},
|
||||
"evmVersion": "byzantium"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
"author": "Jason.Chen",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^4.7.3"
|
||||
"@openzeppelin/contracts": "^4.8.0"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
82
src/ERC1155/JZBG-GOODS.json
Normal file
82
src/ERC1155/JZBG-GOODS.json
Normal file
File diff suppressed because one or more lines are too long
@@ -7,9 +7,9 @@ import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/utils/Strings.sol";
|
||||
import "../common/Symbolable.sol";
|
||||
|
||||
contract JZBG is
|
||||
ERC1155,
|
||||
@@ -18,29 +18,70 @@ contract JZBG is
|
||||
ERC1155Supply,
|
||||
ERC1155URIStorage,
|
||||
Ownable,
|
||||
Symbolable
|
||||
IERC1155Receiver
|
||||
{
|
||||
using Strings for uint256;
|
||||
|
||||
uint256 private _total;
|
||||
uint256 private _count;
|
||||
string private _name;
|
||||
string private _symbol;
|
||||
|
||||
/**
|
||||
* @dev Jing Zhong Bao Guo,JZBG,https://ipfs.jzbg.org/
|
||||
* MINT: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,1234
|
||||
* 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,1,1234567890
|
||||
* TRANSFER: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,5,0x
|
||||
* mintBatch: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,[1,2,3,4],[100,2000,30000,400000]
|
||||
* safeTransferToAddresses: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,[0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB],1,200
|
||||
*/
|
||||
constructor(
|
||||
string memory name_,
|
||||
string memory symbol_,
|
||||
string memory uri_
|
||||
) Symbolable(name_, symbol_) ERC1155(uri_) {
|
||||
) ERC1155(uri_) {
|
||||
_name = name_;
|
||||
_symbol = symbol_;
|
||||
ERC1155URIStorage._setBaseURI(uri_);
|
||||
}
|
||||
|
||||
function name() public view virtual returns (string memory) {
|
||||
return _name;
|
||||
}
|
||||
|
||||
function symbol() public view virtual returns (string memory) {
|
||||
return _symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 有这两个方法,才可以接收其他代币的转账进来
|
||||
*/
|
||||
function onERC1155Received(
|
||||
address,
|
||||
address,
|
||||
uint256,
|
||||
uint256,
|
||||
bytes calldata
|
||||
) public view virtual override returns (bytes4) {
|
||||
return IERC1155Receiver.onERC1155Received.selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 有这两个方法,才可以接收其他代币的转账进来
|
||||
*/
|
||||
function onERC1155BatchReceived(
|
||||
address,
|
||||
address,
|
||||
uint256[] calldata,
|
||||
uint256[] calldata,
|
||||
bytes calldata
|
||||
) public view virtual override returns (bytes4) {
|
||||
return IERC1155Receiver.onERC1155BatchReceived.selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 从合约中转出NFT
|
||||
*/
|
||||
function tranferNFT(
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
) public virtual onlyOwner {
|
||||
_safeTransferFrom(address(this), to, tokenId, amount, "");
|
||||
}
|
||||
|
||||
function setURI(uint256 tokenId, string memory tokenURI)
|
||||
public
|
||||
virtual
|
||||
|
||||
73
src/ERC20/MyERC20.json
Normal file
73
src/ERC20/MyERC20.json
Normal file
File diff suppressed because one or more lines are too long
42
src/ERC20/MyERC20.sol
Normal file
42
src/ERC20/MyERC20.sol
Normal file
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
contract MyERC20 is
|
||||
ERC20,
|
||||
ERC20Burnable,
|
||||
ERC20Pausable,
|
||||
ERC20Snapshot,
|
||||
Ownable
|
||||
{
|
||||
uint8 private _decimals;
|
||||
|
||||
constructor(
|
||||
string memory name_,
|
||||
string memory symbol_,
|
||||
uint256 totalSupply_,
|
||||
uint8 decimals_
|
||||
) ERC20(name_, symbol_) {
|
||||
_decimals = decimals_;
|
||||
_mint(msg.sender, totalSupply_);
|
||||
}
|
||||
|
||||
function decimals() public view virtual override returns (uint8) {
|
||||
return _decimals;
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
) internal virtual override(ERC20, ERC20Pausable, ERC20Snapshot) {
|
||||
ERC20Pausable._beforeTokenTransfer(from, to, amount);
|
||||
ERC20Snapshot._beforeTokenTransfer(from, to, amount);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
abstract contract Symbolable {
|
||||
abstract contract Metadata {
|
||||
string private _name;
|
||||
|
||||
string private _symbol;
|
||||
78
src/common/Ownable.sol
Normal file
78
src/common/Ownable.sol
Normal file
@@ -0,0 +1,78 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/utils/Context.sol";
|
||||
|
||||
/**
|
||||
* @dev Contract module which provides a basic access control mechanism, where
|
||||
* there is an account (an owner) that can be granted exclusive access to
|
||||
* specific functions.
|
||||
*
|
||||
* By default, the owner account will be the one that deploys the contract. This
|
||||
* can later be changed with {transferOwnership}.
|
||||
*
|
||||
* This module is used through inheritance. It will make available the modifier
|
||||
* `onlyOwner`, which can be applied to your functions to restrict their use to
|
||||
* the owner.
|
||||
*/
|
||||
abstract contract Ownable is Context {
|
||||
address private _owner;
|
||||
|
||||
event OwnershipTransferred(
|
||||
address indexed previousOwner,
|
||||
address indexed newOwner
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Initializes the contract setting the deployer as the initial owner.
|
||||
*/
|
||||
constructor() {
|
||||
_transferOwnership(_msgSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Throws if called by any account other than the owner.
|
||||
*/
|
||||
modifier onlyOwner() {
|
||||
_checkOwner();
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the current owner.
|
||||
*/
|
||||
function owner() public view virtual returns (address) {
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Throws if the sender is not the owner.
|
||||
*/
|
||||
function _checkOwner() internal view virtual {
|
||||
require(owner() == _msgSender(), "Ownable: caller is not the owner");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
* Can only be called by the current owner.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public virtual onlyOwner {
|
||||
require(
|
||||
newOwner != address(0),
|
||||
"Ownable: new owner is the zero address"
|
||||
);
|
||||
_transferOwnership(newOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
* Internal function without access restriction.
|
||||
*/
|
||||
function _transferOwnership(address newOwner) internal virtual {
|
||||
address oldOwner = _owner;
|
||||
_owner = newOwner;
|
||||
emit OwnershipTransferred(oldOwner, newOwner);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@openzeppelin/contracts@^4.7.3":
|
||||
version "4.7.3"
|
||||
resolved "https://registry.npmmirror.com/@openzeppelin/contracts/-/contracts-4.7.3.tgz#939534757a81f8d69cc854c7692805684ff3111e"
|
||||
integrity sha512-dGRS0agJzu8ybo44pCIf3xBaPQN/65AIXNgK8+4gzKd5kbvlqyxryUYVLJv7fK98Seyd2hDZzVEHSWAh0Bt1Yw==
|
||||
"@openzeppelin/contracts@^4.8.0":
|
||||
version "4.8.0"
|
||||
resolved "https://registry.npmmirror.com/@openzeppelin/contracts/-/contracts-4.8.0.tgz#6854c37df205dd2c056bdfa1b853f5d732109109"
|
||||
integrity sha512-AGuwhRRL+NaKx73WKRNzeCxOCOCxpaqF+kp8TJ89QzAipSwZy/NoflkWaL9bywXFRhIzXt8j38sfF7KBKCPWLw==
|
||||
|
||||
Reference in New Issue
Block a user