Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created December 27, 2021 22:07
Show Gist options
  • Save z0r0z/c99d3f9a1cef7f8b8bf91dcb8132c80b to your computer and use it in GitHub Desktop.
Save z0r0z/c99d3f9a1cef7f8b8bf91dcb8132c80b to your computer and use it in GitHub Desktop.
NFT that is a social graph where ID holders can add new ID holders through overridden transfers
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import "https://github.com/Rari-Capital/solmate/blob/audit-fixes/src/tokens/ERC721.sol";
/// @notice NFT that is a social graph where ID holders can add new ID holders.
contract SocialGraphNFT is ERC721("Social Graph NFT", "SGNFT") {
string public baseURI;
uint256 public tokenIdCounter;
constructor(string memory baseURI_) {
baseURI = baseURI_;
_mint(msg.sender, tokenIdCounter++);
}
function tokenURI(uint256) public view override returns (string memory) {
return baseURI;
}
function transferFrom(
address from,
address to,
uint256 id
) public override {
_check(from, id);
_mint(to, tokenIdCounter++);
}
function safeTransferFrom(
address from,
address to,
uint256 id
) public override {
_check(from, id);
_mint(to, tokenIdCounter++);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes memory data
) public override {
_check(from, id);
_safeMint(to, tokenIdCounter++, data);
}
function _check(address from, uint256 id) internal view {
require(from == ownerOf[id], "NOT_OWNER");
require(
msg.sender == from || msg.sender == getApproved[id] || isApprovedForAll[from][msg.sender],
"NOT_APPROVED"
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment