From bc6fd803e5e6c71969575272a7c6ba235dc26967 Mon Sep 17 00:00:00 2001 From: wangyusong Date: Tue, 27 Sep 2022 14:49:58 +0800 Subject: [PATCH] add week1 --- README.md | 3 +++ week1/nft.sol | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 week1/nft.sol diff --git a/README.md b/README.md index aad942b..48f1317 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # roadtoweb3 The alchemy Challenges + +# This is the repo for Road to web3 Chanllenges by Alchemy +See [welcome-to-the-road-to-web3](https://docs.alchemy.com/docs/welcome-to-the-road-to-web3) diff --git a/week1/nft.sol b/week1/nft.sol new file mode 100644 index 0000000..334f476 --- /dev/null +++ b/week1/nft.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "@openzeppelin/contracts@4.7.3/token/ERC721/ERC721.sol"; +import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721Enumerable.sol"; +import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721URIStorage.sol"; +import "@openzeppelin/contracts@4.7.3/token/ERC721/extensions/ERC721Burnable.sol"; +import "@openzeppelin/contracts@4.7.3/access/Ownable.sol"; +import "@openzeppelin/contracts@4.7.3/utils/Counters.sol"; + +/// @custom:security-contact wangyusong.com@gmail.com +contract Week1 is ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Burnable, Ownable { + using Counters for Counters.Counter; + + Counters.Counter private _tokenIdCounter; + + constructor() ERC721("Alchemy", "ALCH") {} + + function safeMint(address to, string memory uri) public onlyOwner { + uint256 tokenId = _tokenIdCounter.current(); + _tokenIdCounter.increment(); + _safeMint(to, tokenId); + _setTokenURI(tokenId, uri); + } + + // The following functions are overrides required by Solidity. + + function _beforeTokenTransfer(address from, address to, uint256 tokenId) + internal + override(ERC721, ERC721Enumerable) + { + super._beforeTokenTransfer(from, to, tokenId); + } + + function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { + super._burn(tokenId); + } + + function tokenURI(uint256 tokenId) + public + view + override(ERC721, ERC721URIStorage) + returns (string memory) + { + return super.tokenURI(tokenId); + } + + function supportsInterface(bytes4 interfaceId) + public + view + override(ERC721, ERC721Enumerable) + returns (bool) + { + return super.supportsInterface(interfaceId); + } +}