Skip to content

Instantly share code, notes, and snippets.

@pvinis
Created January 13, 2022 19:00
Show Gist options
  • Save pvinis/204289a5c4e56721be522a9fafad7839 to your computer and use it in GitHub Desktop.
Save pvinis/204289a5c4e56721be522a9fafad7839 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol";
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";
import "@openzeppelin/[email protected]/utils/Counters.sol";
contract amaziNgFreakingarT is ERC721, ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("amaziNgFreakingarT", "ART") {}
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 _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);
}
}
contract ArtsyNFTSales {
// hardcode the "gallery" address
address public constant GALLERY_ADDR = 0xbC19Bd22fefcbC9a62d8DF37a7eBdC1f3510c9df;
address public constant NFT_CONTRACT = 0xF7e5d002E621626F66882413754b80a57461BD99;
////// add a boolean for sale or not
uint public tokenID;
uint public price;
modifier onlyBy(address account) {
require(account == msg.sender, "Only the gallery can do that.");
_;
}
event TokenForSale(uint tokenID, uint price);
event TokenRemovedFromSale(uint tokenID);
receive() external payable {
if (msg.value != price) {
revert("Wrong price!");
}
// whatever money comes to the contract, it goes to the gallery
(bool success,) = payable(GALLERY_ADDR).call{value: msg.value}("");
require(success);
amaziNgFreakingarT nftcontract = amaziNgFreakingarT(NFT_CONTRACT);
nftcontract.safeTransferFrom(GALLERY_ADDR, msg.sender, tokenID);
_removeFromSale(tokenID);
}
// Stores a new value in the contract
function putForSale(uint _tokenID, uint256 _price) public onlyBy(GALLERY_ADDR) {
price = _price;
tokenID = _tokenID;
// amaziNgFreakingarT nftcontract = amaziNgFreakingarT(NFT_CONTRACT);
// nftcontract.approve(address(this), _tokenID);
emit TokenForSale(_tokenID, _price);
}
function removeFromSale(uint _tokenID) public onlyBy(GALLERY_ADDR) {
_removeFromSale(_tokenID);
}
function isForSale() public view returns(bool) {
return price != 0;
}
function priceFor() public view returns(uint256) {
return price;
}
// INTERNAL FUNCS
function _removeFromSale(uint _tokenID) private {
price = 0;
emit TokenRemovedFromSale(_tokenID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment