facebook

Developing a Peer-to-Peer Car Rental System on Blockchain (with Code)

Posted By : Yogesh

Apr 30, 2025

The world is shifting towards decentralized blockchain solutions, and peer-to-peer services are at the forefront of this transformation. One particularly exciting application is a decentralized peer-to-peer car rental system, where users can list, rent, and return vehicles — all without relying on traditional intermediaries — powered entirely by smart contracts. This dApp enables car owners and renters to connect directly, eliminating the need for centralized companies like Turo, Hertz, or Zipcar. Instead of placing trust in a third party, the system relies on blockchain-based smart contracts to manage:

 

  • Listing cars for rent
  • Processing rental payments and security deposits
  • Starting and ending rental agreements
  • Refunding deposits after car return
  • Tracking user reputation and reviews

 

Why Build a Car Rental System on Blockchain?

 

  • Trustless Transactions — No middleman required
  • Transparency — All terms and transactions are verifiable on-chain
  • Security — Funds are held in escrow by smart contracts
  • Ownership Proof — NFTs can represent cars and rental rights
  • Global Access — Anyone with a wallet can participate

 

Also, Read | Developing a Ride-Sharing App like Uber with Blockchain

 

System Overview

 

Our decentralized car rental system includes:

 

  • Smart Contracts for listing, renting, and returning cars
  • Wallet Integration for direct payments
  • IPFS Support (optional) for storing car images and documents
  • Reputation System using on-chain reviews

 

Flow Diagram:

 

Car Owner → List Car → Set Price, Deposit, Terms
Renter → Browse → Rent → Pay Rental Fee & Deposit
Smart Contract Holds Funds → Starts Rental Timer
Renter Returns Car → Owner Confirms Return
Contract Releases Funds → Both Parties Leave Reviews

 

You may also like | Blockchain Meets Mining Supply Chain for End-to-End Tracking

 

Smart Contract: Core Implementation

 

Here's a basic version of the CarRental smart contract:

 

solidity
CopyEdit// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract CarRental {

    struct Car {
        address payable owner;
        uint256 pricePerDay;
        uint256 securityDeposit;
        bool available;
    }

    struct Rental {
        address renter;
        uint256 startTime;
        uint256 endTime;
        uint256 totalPaid;
        bool active;
    }

    uint256 public carCount;
    mapping(uint256 => Car) public cars;
    mapping(uint256 => Rental) public rentals;

    event CarListed(uint256 indexed carId, address owner, uint256 pricePerDay, uint256 securityDeposit);
    event CarRented(uint256 indexed carId, address renter, uint256 startTime, uint256 endTime);
    event CarReturned(uint256 indexed carId, bool damaged);

    /// List a car
    function listCar(uint256 pricePerDay, uint256 securityDeposit) external {
        carCount++;
        cars[carCount] = Car(
            payable(msg.sender),
            pricePerDay,
            securityDeposit,
            true
        );
        emit CarListed(carCount, msg.sender, pricePerDay, securityDeposit);
    }

    /// Rent a car
    function rentCar(uint256 carId, uint256 rentalDays) external payable {
        Car storage car = cars[carId];
        require(car.available, 'Car not available');

        uint256 totalCost = (car.pricePerDay * rentalDays) + car.securityDeposit;
        require(msg.value >= totalCost, 'Insufficient payment');

        rentals[carId] = Rental(
            msg.sender,
            block.timestamp,
            block.timestamp + (rentalDays * 1 days),
            msg.value,
            true
        );

        car.available = false;

        emit CarRented(carId, msg.sender, block.timestamp, block.timestamp + (rentalDays * 1 days));
    }

    /// Return the car
    function returnCar(uint256 carId, bool damaged) external {
        Rental storage rental = rentals[carId];
        Car storage car = cars[carId];

        require(rental.active, 'Rental not active');
        require(rental.renter == msg.sender, 'Not the renter');

        rental.active = false;
        car.available = true;

        if (damaged) {
            // Owner keeps deposit if car is damaged
            car.owner.transfer(rental.totalPaid);
        } else {
            // Refund deposit to renter, rest to owner
            uint256 rentalFee = car.pricePerDay * ((rental.endTime - rental.startTime) / 1 days);
            car.owner.transfer(rentalFee);
            payable(rental.renter).transfer(rental.totalPaid - rentalFee);
        }

        emit CarReturned(carId, damaged);
    }
}

 

Also, Discover | Developing a Food Delivery App like UberEats with Blockchain

 

Conclusion

 

This peer-to-peer car rental system illustrates the power of decentralized applications to disrupt traditional industries. By using smart contracts, users can interact in a trustless, secure, and transparent way, with no need for centralized oversight. With continued development, features like NFT-based ownership, dispute resolution, dynamic pricing, and AI-driven reviews can make such dApps viable real-world alternatives to existing platforms. Blockchain isn't just a trend — it's the foundation of the next generation of digital services. If you have an inventive business idea and want to bring it to reality, leveraging decentralized technologies, connect with our skilled blockchain developers to get started. 

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

May 8, 2025 at 09:22 am

Your comment is awaiting moderation.

bg bg

What's Trending in Tech

bg

Our Offices

India

INDIA

DG-18-009, Tower B,
Emaar Digital Greens, Sector 61,
Gurugram, Haryana
122011.
Unit- 117-120, First Floor,
Welldone Tech Park,
Sector 48, Sohna road,
Gurugram, Haryana
122018.
USA

USA

30N, Gloud St STR E, Sheridan, Wyoming (USA) - 82801
Singapore

SINGAPORE

10 Anson Road, #13-09, International Plaza Singapore 079903.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.

Chat with Us