Untitled
unknown
javascript
a year ago
2.3 kB
14
Indexable
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
/**
* @title BasicNft
* @dev ERC721 implementation for minting NFTs with token URIs.
*/
contract BasicNft is ERC721 {
uint256 private s_tokenCounter;
mapping(uint256 => string) private s_tokenIdToUri;
/**
* @dev Constructor initializes the ERC721 contract with a name and symbol.
*/
constructor() ERC721("Ethereal Artifacts", "ETHA") {
s_tokenCounter = 0;
}
/**
* @notice Mints a new NFT.
* @dev Mints a new NFT with a specified token URI to the recipient address.
* @param recipient The address that will receive the minted NFT.
* @param tokenUri The URI of the token metadata.
*/
function mintNft(address recipient, string memory tokenUri) public {
s_tokenIdToUri[s_tokenCounter] = tokenUri;
_safeMint(recipient, s_tokenCounter);
s_tokenCounter++;
}
/**
* @notice Returns the token URI for a given token ID.
* @dev Overrides the base ERC721 implementation to return the stored token URI.
* @param tokenId The ID of the token.
* @return The token URI.
*/
function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
return s_tokenIdToUri[tokenId];
}
}
---- deploy-----
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Script} from "forge-std/Script.sol";
import {BasicNft} from "../src/BasicNft.sol";
/**
* @title DeployBasicNft
* @dev A script to deploy a BasicNft contract.
*/
contract DeployBasicNft is Script {
/**
* @notice Executes the deployment of a BasicNft contract.
* @dev Deploys a new instance of BasicNft and returns the deployed contract.
* @return The deployed BasicNft contract instance.
*/
function run() external returns (BasicNft) {
vm.startBroadcast(); // Start broadcast execution
BasicNft basicNft = new BasicNft(); // Deploy a new BasicNft contract
vm.stopBroadcast(); // Stop broadcast execution
return basicNft; // Return the deployed BasicNft contract instance
}
}
Editor is loading...
Leave a Comment