Last active
February 8, 2024 01:18
-
-
Save ano/8923c0895f0f11e5e70fb13d33356ddd to your computer and use it in GitHub Desktop.
NFT Birth Certificate Solidity Code
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.0; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract BirthCertificateNFT is ERC721, Ownable { | |
struct BirthCertificate { | |
string childName; | |
uint256 dateOfBirth; | |
string placeOfBirth; | |
string sex; | |
string parent1Name; | |
string parent2Name; | |
// Additional fields such as parent's occupation, address, etc. can be added here | |
} | |
mapping(uint256 => BirthCertificate) private _birthCertificates; | |
uint256 private _tokenCounter; | |
constructor() ERC721("BirthCertificateNFT", "BCNFT") {} | |
function issueBirthCertificate( | |
address recipient, | |
string calldata childName, | |
uint256 dateOfBirth, | |
string calldata placeOfBirth, | |
string calldata sex, | |
string calldata parent1Name, | |
string calldata parent2Name | |
// Additional fields can be added as function parameters | |
) external onlyOwner { | |
_tokenCounter++; | |
_safeMint(recipient, _tokenCounter); | |
_birthCertificates[_tokenCounter] = BirthCertificate(childName, dateOfBirth, placeOfBirth, sex, parent1Name, parent2Name); | |
} | |
function getBirthCertificate(uint256 tokenId) external view returns (BirthCertificate memory) { | |
return _birthCertificates[tokenId]; | |
} | |
// Enable the ABI Encoder v2 | |
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721) returns (bool) { | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment