Last active
March 23, 2023 07:08
-
-
Save Josh4324/7cd6c45c6add09aaf8b48a9a7d7b0967 to your computer and use it in GitHub Desktop.
Contract.sol
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.9; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract SoulBound is ERC721, ERC721URIStorage, Ownable { | |
using Counters for Counters.Counter; | |
Counters.Counter private tokenIds; | |
/** | |
* @dev _baseTokenURI for computing {tokenURI}. If set, the resulting URI for each | |
* token will be the concatenation of the `baseURI` and the `tokenId`. | |
*/ | |
string _baseTokenURI; | |
event Minted(uint256 indexed tokenId, address indexed addr); | |
constructor( | |
string memory baseURI, | |
string memory NFTName, | |
string memory NFTShortName | |
) ERC721(NFTName, NFTShortName) { | |
_baseTokenURI = baseURI; | |
} | |
function mint(address addr) public { | |
uint256 newTokenId = tokenIds.current(); | |
_mint(addr, newTokenId); | |
tokenIds.increment(); | |
emit Minted(newTokenId, msg.sender); | |
} | |
function _beforeTokenTransfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) internal virtual { | |
require(from == address(0), "Err: token transfer is BLOCKED"); | |
super._beforeTokenTransfer(from, to, tokenId, 0); | |
} | |
function _burn( | |
uint256 tokenId | |
) internal override(ERC721, ERC721URIStorage) { | |
super._burn(tokenId); | |
} | |
function tokenURI( | |
uint256 tokenId | |
) | |
public | |
view | |
virtual | |
override(ERC721, ERC721URIStorage) | |
returns (string memory) | |
{ | |
return _baseTokenURI; | |
} | |
function setBaseURI(string memory val) public onlyOwner { | |
_baseTokenURI = val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment