Last active
March 9, 2024 07:45
-
-
Save shobhitic/5fc9c0d6796daff052d1cac2118b108d to your computer and use it in GitHub Desktop.
Soulbound or Account bound non transferable NFT - https://youtu.be/90vWC4Z8aPo
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
// Try using this as URI ipfs://bafkreic6ov4qo4ucd4g4uuyve4h72nc4y2lg7ugtq3n3vxnfp3lojvtmdu | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
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 Web3ClubTourToken is ERC721, ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIdCounter; | |
event Attest(address indexed to, uint256 indexed tokenId); | |
event Revoke(address indexed to, uint256 indexed tokenId); | |
constructor() ERC721("Web3 Club Tour", "W3CT") {} | |
function safeMint(address to, string memory uri) public onlyOwner { | |
uint256 tokenId = _tokenIdCounter.current(); | |
_tokenIdCounter.increment(); | |
_safeMint(to, tokenId); | |
_setTokenURI(tokenId, uri); | |
} | |
function burn(uint256 tokenId) external { | |
require(ownerOf(tokenId) == msg.sender, "Only owner of the token can burn it"); | |
_burn(tokenId); | |
} | |
function revoke(uint256 tokenId) external onlyOwner { | |
_burn(tokenId); | |
} | |
function _beforeTokenTransfer(address from, address to, uint256) pure override internal { | |
require(from == address(0) || to == address(0), "Not allowed to transfer token"); | |
} | |
function _afterTokenTransfer(address from, address to, uint256 tokenId) override internal { | |
if (from == address(0)) { | |
emit Attest(to, tokenId); | |
} else if (to == address(0)) { | |
emit Revoke(to, tokenId); | |
} | |
} | |
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); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment