Last active
January 13, 2023 04:39
-
-
Save shobhitic/7308256f537c8d47f6ca1230c1b4a83c to your computer and use it in GitHub Desktop.
Block/Censor NFT marketplaces that don't honour royalties - https://www.youtube.com/watch?v=pdvnUMz1U8o
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/access/Ownable.sol"; | |
import "@openzeppelin/[email protected]/utils/Counters.sol"; | |
contract MyToken is ERC721, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdCounter; | |
mapping (address => bool) public allowedMarketplaces; | |
constructor() ERC721("MyToken", "MTK") {} | |
function safeMint(address to) public onlyOwner { | |
uint256 tokenId = _tokenIdCounter.current(); | |
_tokenIdCounter.increment(); | |
_safeMint(to, tokenId); | |
} | |
function approve(address to, uint256 id) public virtual override { | |
require(allowedMarketplaces[to], "Invalid marketplace, not allowed"); | |
super.approve(to, id); | |
} | |
function setApprovalForAll(address operator, bool approved) public virtual override { | |
require(allowedMarketplaces[operator], "Invalid marketplace, not allowed"); | |
super.setApprovalForAll(operator, approved); | |
} | |
function setAllowedMarketplace(address marketplace, bool allowed) public onlyOwner { | |
allowedMarketplaces[marketplace] = allowed; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/[email protected]/access/Ownable.sol"; | |
import "@openzeppelin/[email protected]/utils/Counters.sol"; | |
contract MyToken is ERC721, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdCounter; | |
mapping (address => bool) public blockedMarketplaces; | |
constructor() ERC721("MyToken", "MTK") {} | |
function safeMint(address to) public onlyOwner { | |
uint256 tokenId = _tokenIdCounter.current(); | |
_tokenIdCounter.increment(); | |
_safeMint(to, tokenId); | |
} | |
function approve(address to, uint256 id) public virtual override { | |
require(!blockedMarketplaces[to], "Invalid marketplace, not allowed"); | |
super.approve(to, id); | |
} | |
function setApprovalForAll(address operator, bool approved) public virtual override { | |
require(!blockedMarketplaces[operator], "Invalid marketplace, not allowed"); | |
super.setApprovalForAll(operator, approved); | |
} | |
function setBlockedMarketplace(address marketplace, bool blocked) public onlyOwner { | |
blockedMarketplaces[marketplace] = blocked; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment