Skip to content

kaankacar/Car-Rental-Platform-Contract-and-Test-Results

Repository files navigation

Car Rental Platform

The Car Rental Platform is a smart contract written in Solidity that enables users to rent cars. It provides functionalities for adding cars, managing user accounts, renting and returning cars, making payments, and handling balances.

Contract Details

  • Contract Address: 0xc31557fEa17c4A0c2a728cb86f6e9bD871341F07
  • Compiler Version: Solidity ^0.8.7
  • License: MIT

Prerequisites

Before using the Car Rental Platform contract, make sure you have the following:

  • A wallet or an account on a compatible blockchain platform.
  • Sufficient BNB to pay for gas fees and make payments.

Contract Functions

Owner Functions

  1. setOwner

    • Modifier: onlyOwner
    • Sets the owner of the contract to a new address.
    • Parameters:
      • newOwner (address): The address of the new contract owner.
    • Usage: Call this function to transfer ownership of the contract.
  2. addUser

    • Adds a new user to the platform.
    • Parameters:
      • name (string): The name of the user.
      • lastname (string): The last name of the user.
    • Usage: Call this function to create a new user account.
  3. addCar

    • Modifier: onlyOwner
    • Adds a new car to the platform.
    • Parameters:
      • name (string): The name of the car.
      • url (string): The URL of the car's image.
      • rent (uint): The rental fee for the car.
      • sale (uint): The sale fee for the car.
    • Usage: Call this function to add a new car to the platform.
  4. editCarMetaData

    • Modifier: onlyOwner, existingCar
    • Edits the metadata of a car.
    • Parameters:
      • id (uint): The ID of the car to be edited.
      • name (string): The new name for the car.
      • imgUrl (string): The new URL for the car's image.
      • rentFee (uint): The new rental fee for the car.
      • saleFee (uint): The new sale fee for the car.
    • Usage: Call this function to modify the metadata of a car.
  5. editCarStatus

    • Modifier: onlyOwner, existingCar
    • Edits the status of a car.
    • Parameters:
      • id (uint): The ID of the car to be edited.
      • status (Status): The new status of the car (Retired, InUse, or Available).
    • Usage: Call this function to update the status of a car.
  6. withdrawOwnerBalance

    • Modifier: onlyOwner
    • Withdraws the contract's balance to the owner's address.
    • Parameters:
      • amount (uint): The amount of BNB to withdraw.
    • Usage: Call this function to transfer the contract's balance to the owner.

Query Functions

  1. getOwner

    • Retrieves the address of the contract owner.
    • Usage: Call this function to get the address of the contract owner.
  2. getUser

    • Retrieves user information based on the wallet address.
    • Parameters:
      • walletAddress (address): The wallet address of the user.
    • Usage: Call this function to retrieve information about a specific user.
  3. getCar

    • Retrieves car information based on the car ID.
    • Parameters:
      • id (uint): The ID of the car.
    • Usage: Call this function to retrieve information about a specific car.
  4. getCarByStatus

    • Retrieves an array of cars with the specified status.
    • Parameters:
      • _status (Status): The status of the cars to retrieve (Retired, InUse, or Available).
    • Usage: Call this function to get an array of cars with the specified status.
  5. getCurrentCount

    • Retrieves the current count of cars.
    • Usage: Call this function to get the current count of cars.
  6. getContractBalance

    • Modifier: onlyOwner
    • Retrieves the balance of the contract.
    • Usage: Call this function to get the balance of the contract.
  7. getTotalPayment

    • Modifier: onlyOwner
    • Retrieves the total payment made by users.
    • Usage: Call this function to get the total payment made by users.

BNB Smart Chain Truffle Box

Table of contents generated with markdown-toc

This Truffle BNB Smart Chain box provides you with the boilerplate structure necessary to start coding on the BNB Smart Chain. For detailed information on how the BNB Smart Chain works, please see their documentation here.

As a starting point, this box contains only the SimpleStorage Solidity contract. Including minimal code was a conscious decision as this box is meant to provide the initial building blocks needed to get to work on BNB Smart Chain without pushing developers to write any particular sort of application. With this box, you will be able to compile, migrate, and test Solidity code against several instances of BNB Smart Chain networks.

The BNB Smart Chain is fully compatible with the EVM. This means you will not need a new compiler to deploy Solidity contracts, and should be able to add your own Solidity contracts to this project. The main difference developers will encounter is in accessing and interacting with the BNB Smart Chain network.

Requirements

The BSC box has the following requirements:

  • Node.js 10.x or later
  • NPM version 5.2 or later
  • Windows, Linux or MacOS

Helpful, but optional:

Installation

truffle unbox bnb-chain/BSC-Truffle-Starter-Box

Setup

Using the env File

You will need at least one mnemonic to use with the network. The .dotenv npm package has been installed for you, and you will need to create a .env file for storing your mnemonic and any other needed private information.

The .env file is ignored by git in this project, to help protect your private data. In general, it is good security practice to avoid committing information about your private keys to github. The truffle-config.bsc.js file expects a MNEMONIC value to exist in .env for running migrations on the networks listed in truffle-config.bsc.js.

If you are unfamiliar with using .env for managing your mnemonics and other keys, the basic steps for doing so are below:

  1. Use touch .env in the command line to create a .env file at the root of your project.
  2. Open the .env file in your preferred IDE
  3. Add the following, filling in your own mnemonic:
MNEMONIC="<Your Mnemonic>"
  1. As you develop your project, you can put any other sensitive information in this file. You can access it from other files with require('dotenv').config() and refer to the variable you need with process.env['<YOUR_VARIABLE>'].

New Configuration File

A new configuration file exists in this project: truffle-config.bsc.js. This file contains a reference to the new file location of the contracts_build_directory for BNB Smart Chain contracts and lists several networks that are running the BNB Smart Chain network instance (see below).

Please note, the classic truffle-config.js configuration file is included here as well, because you will eventually want to deploy contracts to on localhost for local development. All normal truffle commands (truffle compile, truffle migrate, etc.) will use this config file and save built files to build/local-contracts. You can save Solidity contracts that you wish to deploy to Ethereum in the contracts/local-dev folder.

New Directory Structure for Artifacts

When you compile or migrate, the resulting json files will be at build/bsc-contracts/. This is to distinguish them from contracts you build for any other network other than BSC. As we have included the appropriate contracts_build_directory in each configuration file, Truffle will know which set of built files to reference!

BNB Smart Chain

Compiling

You do not need to add any new compilers or settings to compile your contracts for the BNB Smart Chain, as it is fully EVM compatible. The truffle-config.bsc.js configuration file indicates the contract and build paths for BSC-destined contracts.

If you are compiling contracts specifically for the BNB Smart Chain network, use the following command, which indicates the appropriate configuration file:

npm run compile:bsc

If you would like to recompile previously compiled contracts, you can manually run this command with truffle compile --config=truffle-config.bsc.js and add the --all flag.

Migrating

To migrate on the BNB Smart Chain network, run npm run migrate:bsc --network=(bscTestnet | bscMainnet) (remember to choose a network from these options!).

As you can see, you have two BSC networks to choose from:

  • bscTestnet: This is the BNB Smart Chain testnet.
  • bscMainnet: This is the BNB Smart Chain mainnet. Caution! If you deploy to this network using a connected wallet, the fees are charged in mainnet BNB.

If you would like to migrate previously migrated contracts on the same network, you can run truffle migrate --config truffle-config.bsc.js --network= (bscTestnet | bscMainnet) and add the --reset flag.

Paying for Migrations

To pay for your deployments, you will need to have an account with BNB available to spend. You will need your mnemomic phrase (saved in the .env file or through some other secure method). The first account generated by the seed needs to have the BNB you need to deploy.

If you do not have a wallet with funds to deploy, you will need to connect a wallet to at least one of the networks above. For testing, this means you will want to connect a wallet to the BSC Testnet network. We recommend using MetaMask.

Documentation for how to set up MetaMask to configure custom network like BSc Testnet can be found here.

Follow the steps in the documentation above using the BNB Smart Chain RPC endpoints (https://docs.bnbchain.org/docs/rpc). The chainId values are the same as those in the truffle-config.bsc.js networks entries.

To get testnet BNB tokens use the official faucet.

Basic Commands

The code here will allow you to compile, migrate, and test your code on the BNB Smart Chain. The following commands can be run (more details on each can be found in the next section):

To compile:

npm run compile:bsc

To migrate:

npm run migrate:bsc --network=(bscTestnet | bscMainnet)

To test:

npm run test:bsc --network=(bscTestnet | bscMainnet)

Testing

In order to run the test currently in the boilerplate, use the following command: npm run test:bsc --network=(bscTestnet | bscMainnet) (remember to choose a network!). The current test file just has some boilerplate tests to get you started. You will likely want to add network-specific tests to ensure your contracts are behaving as expected.

Support

Support for this box is available via the Truffle community here or on our official Discord Channel.

About

The Car Rental Platform is a decentralized smart contract on BNB Chain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published