三种token合约的一个demo

This commit is contained in:
2022-11-14 16:53:17 +08:00
parent 441332e26d
commit 6f28e5b0bd

106
src/ERC721/MyERC721.sol Normal file
View File

@@ -0,0 +1,106 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyERC721 is
ERC721,
IERC721Receiver,
ERC721Enumerable,
ERC721Pausable,
ERC721Holder,
Ownable
{
// onERC721Received
string private _address;
string private _baseUri;
constructor(
string memory name_,
string memory symbol_,
string memory baseUri_
) ERC721(name_, symbol_) {
setBaseURI(baseUri_);
}
/**
* @dev 铸造NFT
*/
function safeMint(address to, uint256 tokenId) public virtual onlyOwner {
_safeMint(to, tokenId);
}
/**
* @dev 燃烧NFT
*/
function burn(uint256 tokenId) public virtual {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: caller is not token owner or approved"
);
_burn(tokenId);
}
/**
* @dev 从合约中转出NFT
*/
function tranferNFT(address to, uint256 tokenId) public virtual onlyOwner {
_safeTransfer(address(this), to, tokenId, "");
}
/**
* @dev 设置TOKEN的URI
*/
function setBaseURI(string memory baseUri_) public virtual onlyOwner {
_baseUri = baseUri_;
}
/**
* @dev 暂停交易
*/
function pause() public virtual onlyOwner {
_pause();
}
/**
* @dev 解除暂停
*/
function unpause() public virtual onlyOwner {
_unpause();
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseUri;
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, ERC721Enumerable)
returns (bool)
{
return ERC721Enumerable.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) {
ERC721Pausable._beforeTokenTransfer(from, to, firstTokenId, batchSize);
ERC721Enumerable._beforeTokenTransfer(
from,
to,
firstTokenId,
batchSize
);
}
}