A decentralized marketplace for buying and selling vehicles using blockchain technology and NFTs.
This project creates a decentralized car marketplace where:
- Dealers can register and list vehicles for sale
- Each vehicle is represented as a unique NFT (Non-Fungible Token)
- Buyers can purchase vehicles directly through smart contracts
- Vehicle history and ownership is transparently tracked on the blockchain
- NFT-Based Vehicle Representation: Each car is a unique digital asset with verifiable ownership
- Dealer Registration System: Verified sellers with deposit requirements
- Transparent Vehicle History: Immutable record of ownership and service history
- Direct Peer-to-Peer Transactions: No intermediaries needed for buying/selling
- On-Chain & Off-Chain Data: Efficient storage of vehicle information
- User-Friendly Interface: Abstract blockchain complexity from end users
-
CarMarketplaceNFT Contract:
- Inherits from OpenZeppelin's ERC721 standard
- Handles minting, ownership, and transfers of vehicle NFTs
- Manages vehicle metadata and on-chain information
-
Key Data Structures:
struct CarInfo { string make; string model; uint256 year; string vin; uint256 price; address dealer; bool forSale; } struct Dealer { string email; string name; uint256 registrationTimestamp; uint256 depositAmount; bool isActive; }
-
Dealer Registration:
function registerDealer(string memory _email, string memory _name) external payable
-
Vehicle Listing (NFT Minting):
function mintCarNFT( string memory _make, string memory _model, uint256 _year, string memory _vin, uint256 _price, string memory _tokenURI ) external onlyRegisteredDealer returns (uint256)
-
Purchase System:
function buyCar(uint256 _tokenId) external payable
-
Vehicle History Tracking:
function addCarHistory(uint256 _tokenId, string memory _eventType, string memory _description) external
- Node.js and npm
- Solidity development environment (Truffle, Hardhat, or Remix)
- MetaMask or similar Web3 wallet
- IPFS account for metadata storage (Pinata recommended)
-
Clone the repository:
git clone https://github.com/yourusername/web3-car-marketplace.git cd web3-car-marketplace -
Install dependencies:
npm install npm install @openzeppelin/contracts
-
Configure environment:
cp .env.example .env # Edit .env with your variables -
Compile contracts:
npx hardhat compile # or using truffle truffle compile -
Deploy contracts:
npx hardhat run scripts/deploy.js --network [network] # or using truffle truffle migrate --network [network]
- Open Remix IDE
- Create a new file named
CarMarketplaceNFT.sol - Import OpenZeppelin dependencies (Either by installing via Package Manager or using GitHub URLs):
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; // For older versions: import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/contracts/utils/Counters.sol";
- Compile and deploy using Remix deployment tab
-
Prepare Metadata:
- Create JSON file with vehicle details:
{ "name": "2023 Tesla Model 3", "description": "Electric sedan with 82k miles", "image": "ipfs://bafybeihvhgwkl54...", "attributes": [ {"trait_type": "Make", "value": "Tesla"}, {"trait_type": "Model", "value": "Model 3"}, {"trait_type": "Year", "value": "2023"}, {"trait_type": "VIN", "value": "5YJ3E1EA5PF..."}, {"trait_type": "Mileage", "value": "82000"} ] } - Upload to IPFS to get a CID (Content Identifier)
- Create JSON file with vehicle details:
-
Register as Dealer:
- Pay registration fee
- Provide required information
-
Mint Vehicle NFT:
- Call
mintCarNFTfunction with vehicle details - Include IPFS URI as
_tokenURIparameter
- Call
-
List for Sale:
- Set price and availability
-
Browse Listings:
- View available vehicles
- Check details and ownership history
-
Purchase:
- Call
buyCarfunction with the vehicle's token ID - Include required payment amount
- Call
-
Transfer:
- NFT transfers to buyer's wallet
- Payment transfers to seller
- Ownership record updated on blockchain
- Escrow Mechanism: Consider adding escrow for high-value transactions
- Validation: Include additional VIN validation
- Upgradability: Plan for contract upgrades as needed
- Gas Optimization: Store minimal data on-chain, use IPFS for details
- Price Oracles: For supporting multiple payment tokens
- Dispute Resolution: Add mechanism for resolving transaction disputes
- Fractional Ownership: Enable multiple people to own shares of vehicles
- Integration with DeFi: Add financing options for vehicle purchases
- IoT Integration: Connect with vehicle telematics for real-time data
- Cross-Chain Support: Enable NFTs to work across multiple blockchains
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Your Name - @yourtwitter - email@example.com