Phrase Trade NFT
Overview
The PhraseTradeNFT
contract is a specialized implementation of the ERC-721 standard for non-fungible tokens (NFTs). It enables the creation, storage, and management of NFTs within the PhraseTrade ecosystem. The contract extends the functionality provided by ERC721URIStorage
and includes additional features such as a controllable minting process and a customizable base URI for metadata. The contract is designed to be owned and controlled by a specified controller, ensuring secure and authorized operations.
Table of Contents
Contract Inheritance
State Variables
Modifiers
Constructor
Public and External Functions
Controller Management
Base Token URI Management
Token Minting
Token URI Retrieval
Events
Contract Inheritance
The PhraseTradeNFT
contract inherits from the following contracts:
Ownable
: Provides basic access control where there is an owner account that can be granted exclusive access to specific functions.ERC721URIStorage
: An extension of the ERC721 standard that allows each token to have a unique URI, typically pointing to the token's metadata.IPhraseTradeNFT
: An interface defining the external functions that thePhraseTradeNFT
contract must implement.
State Variables
address public controller
: This variable stores the address of the controller, which is an entity with specific permissions to mint new tokens. The controller is typically set during contract deployment and can be updated by the owner.string public baseTokenURI
: This variable holds the base URI that is prefixed to the token-specific URI (often a CID) to create the full metadata URI for each token.
Modifiers
onlyController()
: Ensures that only the controller address can invoke certain functions. This modifier is applied to functions where the controller is granted exclusive rights, such as minting new tokens.
Constructor
The constructor initializes the contract by setting the initial controller address and invoking the ERC721 constructor with a specific token name ("PhraseTradeNFT") and symbol ("PTN").
Parameters:
controller_
: The address to be set as the controller, responsible for minting new tokens.
Public and External Functions
Controller Management
setController(address controller_)
Description: Allows the contract owner to set or update the controller address. The controller has the exclusive right to mint new tokens.
Modifiers:
onlyOwner
Parameters:
controller_
: The new controller address.
Base Token URI Management
setBaseTokenURI(string memory _baseTokenURI)
Description: Sets or updates the base token URI, which is prepended to the individual token URIs (CIDs) to form the full metadata URL.
Modifiers:
onlyOwner
Parameters:
_baseTokenURI
: The new base URI to be used for all tokens.
Token Minting
mint(address _to, uint256 _tokenId, string memory _tokenURI)
Description: Mints a new NFT and assigns it to a specified address. This function can only be called by the controller. It sets the token's URI to the provided
_tokenURI
, which typically contains the CID of the metadata file.Modifiers:
onlyController
Parameters:
_to
: The address that will own the newly minted token._tokenId
: The unique identifier for the token (typically the market ID)._tokenURI
: The content identifier (CID) of the token's metadata file.
Token URI Retrieval
tokenURI(uint256 _tokenId)
Description: Retrieves the full metadata URI for a given token ID by concatenating the base token URI with the token-specific URI (CID). If no base URI is set, it returns the CID directly.
Parameters:
_tokenId
: The ID of the token whose URI is to be retrieved.Returns: A string representing the full URI of the token's metadata.
Events
While the contract doesn't explicitly define events, typical events from the inherited ERC721
standard would be applicable:
Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
: Emitted when an NFT is transferred from one address to another.Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)
: Emitted when the owner of an NFT grants another address approval to transfer the NFT.ApprovalForAll(address indexed owner, address indexed operator, bool approved)
: Emitted when the owner sets or unsets an operator as approved to manage all their NFTs.
Summary
The PhraseTradeNFT
contract is a crucial component within the PhraseTrade ecosystem, providing a controlled and secure environment for minting and managing NFTs. By leveraging the ERC721 standard and extending its functionality with URI storage and controllable minting, the contract ensures that NFT creation is both flexible and secure. The integration of a base URI allows for dynamic and scalable management of metadata, supporting the evolving needs of the platform. With clear roles defined for the owner and controller, the contract maintains a balance between flexibility and security, making it suitable for a wide range of NFT-based applications.
Last updated