update
This commit is contained in:
20
.vscode/settings.json
vendored
Normal file
20
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"MicroPython.executeButton": [
|
||||
{
|
||||
"text": "▶",
|
||||
"tooltip": "运行",
|
||||
"alignment": "left",
|
||||
"command": "extension.executeFile",
|
||||
"priority": 3.5
|
||||
}
|
||||
],
|
||||
"MicroPython.syncButton": [
|
||||
{
|
||||
"text": "$(sync)",
|
||||
"tooltip": "同步",
|
||||
"alignment": "left",
|
||||
"command": "extension.execute",
|
||||
"priority": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
123
src/ERC721/SelfMintERC721.sol
Normal file
123
src/ERC721/SelfMintERC721.sol
Normal file
@@ -0,0 +1,123 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
|
||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
||||
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
|
||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
||||
import "../common/Pause.sol";
|
||||
import "../common/Paymentable.sol";
|
||||
|
||||
contract SelfMintERC721 is
|
||||
ERC721,
|
||||
ERC721Burnable,
|
||||
ERC721Enumerable,
|
||||
Ownable,
|
||||
Pause,
|
||||
Paymentable,
|
||||
ERC721Holder,
|
||||
ERC1155Holder
|
||||
{
|
||||
string private _baseUri;
|
||||
|
||||
using Counters for Counters.Counter;
|
||||
|
||||
Counters.Counter private _tokenIdTracker;
|
||||
|
||||
constructor(
|
||||
string memory name_,
|
||||
string memory symbol_,
|
||||
string memory baseUri_
|
||||
) ERC721(name_, symbol_) {
|
||||
_setBaseURI(baseUri_);
|
||||
}
|
||||
|
||||
function mint(address to) public payable virtual {
|
||||
_mint(to, _tokenIdTracker.current());
|
||||
_tokenIdTracker.increment();
|
||||
}
|
||||
|
||||
function supportsInterface(bytes4 interfaceId)
|
||||
public
|
||||
view
|
||||
virtual
|
||||
override(ERC721, ERC1155Receiver, ERC721Enumerable)
|
||||
returns (bool)
|
||||
{
|
||||
return super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 从合约中提取ERC20,因为ERC20转账不会检测是否是合约,是否可以接收代币,不用前置的一些操作
|
||||
*/
|
||||
function transferERC20(
|
||||
address tokenAddress,
|
||||
address to,
|
||||
uint256 amount
|
||||
) public virtual onlyOwner {
|
||||
require(to != address(0), "TRANSFER: to the zero address");
|
||||
IERC20 token = IERC20(tokenAddress);
|
||||
uint256 balance = token.balanceOf(address(this));
|
||||
require(amount <= balance, "TRANSFER: insufficient balance");
|
||||
token.transfer(to, amount);
|
||||
}
|
||||
|
||||
function transferERC721(
|
||||
address tokenAddress,
|
||||
address to,
|
||||
uint256 tokenId
|
||||
) public virtual onlyOwner {
|
||||
require(to != address(0), "TRANSFER: to the zero address");
|
||||
IERC721 token = IERC721(tokenAddress);
|
||||
require(
|
||||
address(this) == token.ownerOf(tokenId),
|
||||
"TRANSFER: transfer from incorrect owner"
|
||||
);
|
||||
token.transferFrom(address(this), to, tokenId);
|
||||
}
|
||||
|
||||
function transferERC1155(
|
||||
address tokenAddress,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
uint256 amount
|
||||
) public virtual onlyOwner {
|
||||
require(to != address(0), "TRANSFER: to the zero address");
|
||||
IERC1155 token = IERC1155(tokenAddress);
|
||||
require(
|
||||
amount <= token.balanceOf(address(this), tokenId),
|
||||
"TRANSFER: insufficient balance"
|
||||
);
|
||||
token.safeTransferFrom(address(this), to, tokenId, amount, bytes(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 设置TOKEN的URI
|
||||
*/
|
||||
function setBaseURI(string memory baseUri_) public virtual onlyOwner {
|
||||
_setBaseURI(baseUri_);
|
||||
}
|
||||
|
||||
function _setBaseURI(string memory baseUri_) internal virtual {
|
||||
_baseUri = baseUri_;
|
||||
}
|
||||
|
||||
function _baseURI() internal view virtual override returns (string memory) {
|
||||
return _baseUri;
|
||||
}
|
||||
|
||||
function _beforeTokenTransfer(
|
||||
address from,
|
||||
address to,
|
||||
uint256 firstTokenId,
|
||||
uint256 batchSize
|
||||
) internal virtual override(ERC721, ERC721Pausable, ERC721Enumerable) {
|
||||
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user