Skip to content

Instantly share code, notes, and snippets.

@malipetek
Created November 30, 2022 07:52
Show Gist options
  • Save malipetek/51aa298553f53bb5dd65532c86292a12 to your computer and use it in GitHub Desktop.
Save malipetek/51aa298553f53bb5dd65532c86292a12 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts@4.6.0/security/Pausable.sol";
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts@4.6.0/utils/Counters.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol";
/// @custom:security-contact nft@chateaumeaume.com/
contract ChateauMeaumeWines is ERC721, ERC721Enumerable, Pausable, Ownable, ERC721Burnable, ERC721URIStorage {
using Counters for Counters.Counter;
string baseURI;
Counters.Counter private _tokenIdCounter;
string private _contact_url = "https://chateaumeaume.com/en/contact/";
constructor() ERC721("Chateau Meaume Wines", "CMW") {}
function setTokenURI(
uint256 tokenId,
string memory _tokenURI
) external {
_setTokenURI(tokenId, _tokenURI);
// _setTokenURI(tokenId, ));
}
function setBaseURI(string memory baseURI_) external {
baseURI = baseURI_;
}
function _baseURI() internal view override returns (string memory) {
return baseURI;
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
_burn(tokenId);
}
function renounceOwnership() public virtual onlyOwner override (Ownable) {
// disabled
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return string(abi.encodePacked(baseURI, "/", tokenId, ".json"));
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
whenNotPaused
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
function getTokenIds(address _owner) public view returns (uint[] memory) {
uint[] memory _tokensOfOwner = new uint[](ERC721.balanceOf(_owner));
uint i;
for (i=0;i<ERC721.balanceOf(_owner);i++){
_tokensOfOwner[i] = ERC721Enumerable.tokenOfOwnerByIndex(_owner, i);
}
return (_tokensOfOwner);
}
function getLastMintedTokenId() public view returns (uint256) {
return _tokenIdCounter.current();
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function contact() public view virtual returns (string memory) {
return _contact_url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment