Skip to content

Instantly share code, notes, and snippets.

@Jayke770
Created September 8, 2023 02:57
Show Gist options
  • Select an option

  • Save Jayke770/98146401e75060368f4ef88d59f11093 to your computer and use it in GitHub Desktop.

Select an option

Save Jayke770/98146401e75060368f4ef88d59f11093 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.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts@4.9.3/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.9.3/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.9.3/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts@4.9.3/access/Ownable.sol";
import "@openzeppelin/contracts@4.9.3/utils/Counters.sol";
contract Villa is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
string villa_uid;
string villa_name;
uint256 villa_buyPrice;
uint256 villa_sellPrice;
string villa_uri;
uint256 villa_max_nft_count;
uint256 villa_minted_nft;
mapping(address => bool) public admins;
constructor(
address[] memory _admins,
string memory _name,
string memory _symbol) ERC721(_name, _symbol) {
// set msg.sender as admin
require(!admins[msg.sender], "Duplicate admin");
admins[msg.sender] = true;
for (uint256 i = 0; i < _admins.length; i++) {
require(!admins[_admins[i]], "Duplicate admin");
admins[_admins[i]] = true;
}
}
modifier onlyAdmin() {
require(admins[msg.sender], "admin only");
_;
}
function initializeVilla(
string memory _uid,
string memory _name,
string memory _uri,
uint256 _buyPrice,
uint256 _sellPrice,
uint256 _max_nft_count
) public onlyOwner {
villa_uid = _uid;
villa_name = _name;
villa_uri = _uri;
villa_max_nft_count = _max_nft_count;
villa_buyPrice = _buyPrice;
villa_sellPrice = _sellPrice;
villa_minted_nft = 0;
}
function safeMint(address to, string memory uri) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
function addAdmin(address _new_admin) public onlyOwner {
require(!admins[_new_admin], "already admin");
admins[_new_admin] = true;
}
// The following functions are overrides required by Solidity.
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, ERC721URIStorage)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment