Skip to content

Instantly share code, notes, and snippets.

@shobhitic
Last active January 13, 2023 04:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shobhitic/7308256f537c8d47f6ca1230c1b4a83c to your computer and use it in GitHub Desktop.
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
// 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/access/Ownable.sol";
import "@openzeppelin/contracts@4.7.3/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;
}
}
// 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/access/Ownable.sol";
import "@openzeppelin/contracts@4.7.3/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