Posted By : Yogesh
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:
Also, Read | Developing a Ride-Sharing App like Uber with Blockchain
Our decentralized car rental system includes:
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
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
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.
May 8, 2025 at 09:22 am
Your comment is awaiting moderation.