RealEstateMarketplace is a decentralized application (dApp) that allows users to mint, list, buy, and sell real estate assets as NFTs (Non-Fungible Tokens) on the Ethereum blockchain. The project leverages smart contracts, IPFS for decentralized storage, and a frontend built with Next.js and Tailwind CSS.
- Mint NFTs: Users can mint new real estate NFTs by providing metadata and images.
- List NFTs: Users can list their real estate NFTs for sale on the marketplace.
- Buy NFTs: Users can purchase listed real estate NFTs.
- Cancel Listings: Users can cancel their listings.
- Update Listings: Users can update the price of their listed NFTs.
- View Listings: Users can view all listed real estate NFTs.
blockchain/
contracts/
Assest.sol
RealEstateMarketplace.sol
deploy/
00-deploy-assest.js
01-deploy-realestatemarketplace.js
utils/
verify.js
hardhat.config.js
helper-hardhat-config.js
frontend/
components/
Footer.js
Header.js
NFTBox.js
UpdateListingModal.js
constants/
RealEstateMarketplace.json
Assest.json
networkMapping.json
subgraphQueries.js
pages/
index.js
sell-nft.js
OwnerDetailForm.js
property-Listing.js
graphExample.js
styles/
Home.module.css
globals.css
addEvents.js
next.config.js
tailwind.config.js
package.json
server/
controllers/
uploadController.js
middleware/
multer.js
uploadToPinata.js
routes/
uploadRoute.js
index.js
package.json
- Node.js
- npm or yarn
- Hardhat
- Metamask (for interacting with the dApp)
-
Clone the repository:
git clone <repository-url> cd blockchain
-
Install dependencies:
npm install
-
Compile the smart contracts:
yarn hardhat compile
-
Deploy the smart contracts:
yarn hardhat deploy --network <network-name>
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Create a .env file and add your environment variables:
cp .env.example .env
-
Start the development server:
npm run dev
-
Navigate to the server directory:
cd server
-
Install dependencies:
npm install
-
Create a .env file and add your environment variables:
cp .env.example .env
-
Start the server:
node index.js
The frontend interacts with the blockchain using the react-moralis
library to connect to the Ethereum network and execute smart contract functions. The integration involves the following steps:
- Connecting to the Wallet: The frontend uses Metamask to connect to the user's Ethereum wallet.
- Executing Smart Contract Functions: The
useWeb3Contract
hook fromreact-moralis
is used to call smart contract functions such as minting NFTs, listing items, and buying items. - Handling Responses: The frontend handles the responses from the smart contract functions, updating the UI accordingly.
Example of minting an NFT:
const handleMintNft = (data) => {
const tokenUri = data.data[0].inputResult;
const citizenshipId = parseInt(data.data[1].inputResult);
runContractFunction({
params: {
abi: assestAbi,
contractAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
functionName: "mintNft",
params: {
tokenUri: tokenUri,
citizenshipId: citizenshipId,
},
},
onSuccess: () => alert("NFT Minted Successfully!"),
onError: (error) => console.log(error),
});
};
The server part of the application handles file uploads and interacts with IPFS through Pinata for decentralized storage. It uses Express.js for handling HTTP requests.
- POST /upload: This route handles file uploads. It uses the
multer
middleware to handle file uploads and theuploadController
to process the uploaded files.
- multer.js: Configures the
multer
middleware for handling file uploads. - uploadToPinata.js: Contains functions for uploading files and metadata to Pinata.
- uploadController.js: Contains the logic for processing uploaded files and storing them on IPFS via Pinata.
- Open the frontend application in your browser.
- Connect your Metamask wallet.
- Use the provided forms to mint, list, buy, and manage real estate NFTs.
- Assest.sol: Implements the ERC721 standard for minting and managing real estate NFTs.
- RealEstateMarketplace.sol: Implements the marketplace functionality for listing, buying, and managing real estate NFTs.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.