Real Estate NFTs Minter

Table of contents

No heading

No headings in the article.

Certainly! Here's an example of a Solidity smart contract for an NFT minter that allows you to mint real estate NFTs with associated metadata and rental terms:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract RealEstateNFT is ERC721URIStorage, Ownable {
    uint256 private _tokenIdCounter;

    struct RealEstate {
        string propertyDetails;
        string imageUrl;
        uint256 rentalPrice; // Rental price in wei
        uint256 rentalDuration; // Rental duration in seconds
    }

    mapping(uint256 => RealEstate) private _realEstates;

    constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {
        _tokenIdCounter = 1;
    }

    function mintRealEstate(
        string memory _propertyDetails,
        string memory _imageUrl,
        uint256 _rentalPrice,
        uint256 _rentalDuration
    ) external onlyOwner returns (uint256) {
        uint256 newTokenId = _tokenIdCounter;
        _safeMint(msg.sender, newTokenId);
        _setTokenURI(newTokenId, _imageUrl);

        _realEstates[newTokenId] = RealEstate({
            propertyDetails: _propertyDetails,
            imageUrl: _imageUrl,
            rentalPrice: _rentalPrice,
            rentalDuration: _rentalDuration
        });

        _tokenIdCounter++;

        return newTokenId;
    }

    function getRealEstate(uint256 _tokenId) external view returns (RealEstate memory) {
        require(_exists(_tokenId), "Invalid token ID");
        return _realEstates[_tokenId];
    }
}

In this example, the contract RealEstateNFT inherits from ERC721URIStorage to implement the ERC721 standard for NFTs. It also inherits from Ownable to restrict the minting functionality to the contract owner.

The contract includes a struct RealEstate to store the metadata and rental terms for each real estate NFT. The mintRealEstate function allows the contract owner to mint new NFTs by providing the necessary details, and the getRealEstate function retrieves the metadata and rental terms of a specific NFT.

Please note that this is a simplified example, and you may need to modify and enhance it to fit your specific requirements. Additionally, you'll need to import the relevant OpenZeppelin contracts (e.g., ERC721URIStorage, Ownable) into your project for it to compile successfully.