I want to implement a Car rental agreement.

In Customer contract there in stract with 4 field. And a registerToProvider function. In Provider contract there are two function to set rent and registration fee. All these are working fine. If a customer register to provider service, and provider set some rent and registration fee it works and in MIST it shows.

But when customer call the payRent or payRegistration fee these are not working and no update on MIST. can u please check my code and say what is the problem.

contract CarRentalServiceCustomer is GeneralAccount{
    string public customerName;
    string public postalAddress;
    string public phoneNumber;
    string public emailAddress;

    mapping(address=>CarRentService) public rentCar;

    struct CarRentService{ 
        bool active;
        uint lastUpdate;
        uint registrationFee;   
        uint rent;              

    function CarRentalServiceCustomer(string _name,string _postalAddress,string _phoneNumber,string _emailAddress){
        customerName  = _name;
        postalAddress = _postalAddress;
        phoneNumber   = _phoneNumber;
        emailAddress  = _emailAddress;

    function registerToCarRentalServiceProvider(address _providerAddress) onlyOwner {

        rentCar[_providerAddress] = CarRentService({
                                    active: true, 
                                    lastUpdate: now,
                                    registrationFee: 0,
                                    rent: 0

    function setRegistrationFee(uint _registrationFee) {
            rentCar[msg.sender].lastUpdate      = now;
            rentCar[msg.sender].registrationFee = _registrationFee;

    function setCarRent(uint _rent) {
            rentCar[msg.sender].lastUpdate = now;
            rentCar[msg.sender].rent       = _rent;

    function payRegistrationFeeToCarRentalServiceProvider(address _providerAddress) returns (bool){

        bool regFeeStatus = true;
            rentCar[_providerAddress].registrationFee = 0;
            return regFeeStatus;
            return !regFeeStatus;

    function payRentToCarRentalServiceProvider(address _providerAddress) returns (bool){

        bool payStatus = true;
            rentCar[_providerAddress].rent = 0;
            return payStatus;
            return !payStatus;

    function unsubscribeFromCarRentalService(address _providerAddress){
        if(rentCar[_providerAddress].active = false && rentCar[_providerAddress].rent == 0 
        && rentCar[_providerAddress].registrationFee == 0 ){
            rentCar[_providerAddress].active = false;
        } else {

when i call these function the transaction works properly but status is not changing. Kindly see the below image. I want after sending the rent both rent and registration fee will be 0.

enter image description here

  • Possible to put the rest of the contract up? This has undefined structs and other issues so it can't compile. We don't see .rent set anywhere and this is a problem ( send(0) ) but it's not necessarily the problem. Need to see what the rest is doing. – Rob Hitchens - B9lab Feb 8 '17 at 22:21
  • I have upload the full code....can please have a look... – TAMIM HAIDER Feb 9 '17 at 8:48
  • Thanks. I got it to compile by removing "is General Account" and the onlyOwner modifers. Good enough for troubleshooting. Found some problems. – Rob Hitchens - B9lab Feb 9 '17 at 8:57
  • Is the problem with Inherent contract or modifier. Modifier is imp for security. Sorry i am totally a newbie. Please feel free to suggest me to develop this contract. – TAMIM HAIDER Feb 9 '17 at 9:17
  • I have a plan to add some functionalities like #customer can choose car # for example provider has 5 car then customer can not rent the car and a message will shoe all cars booked. #provider has a database how many customer is registered in the service.... But how can i map that i have no idea.... – TAMIM HAIDER Feb 9 '17 at 9:29

I'm fairly confused about what's supposed to be going on. Missing "GeneralAccount", so assuming that's where the payable functions are.

After some fiddling, I found the sequence but I'm very confused about who's who and why we're doing certain things.

I made minor changes to support the test:

  1. Removed is GeneralAccount (missing)
  2. Removed onlyOwner (missing)
  3. Added a do-nothing function payTestFunds() payable.


I looked at the various things that have to happen first for this function to work, and came up with a sequence:

  1. Sent contract some Eth with the payable function I added. Quite important, because if the contract doesn't have money, the send() will fail.
  2. Sent my address to registerToCarRentalServiceProvider

enter image description here

  1. Sent "1" to setCarRent enter image description here

  2. Checked rentCar[myAddress]. 1. Correct. enter image description here

  3. Sent my address to payRentToCarRentalServiceProvider enter image description here

  4. Checked rentCar[myAddress]. 0. Correct. enter image description here

I'm having trouble following the business logic of it but it is setting the values as expected.

The functions that send() are structurally unsafe but it's off topic so setting it aside.

Hope it helps.

  • I guess this is the problem. I have the contract GeneralAccount and its modifier onlyowner also. My Customer contract inherit that contract. I guess my problem is i didnt give any ether to my contract account. i thought the ether of send function will deduct from my external account. I was wrong. Now when i deploy my customer contract with some ethar i am getting the following error in my MIST wallet. "It seem this transaction will fail, if "you submit it , it may consume all the gas you send."....and i have added the following payable function function payTestFunds() payable{ } Tnx a lot – TAMIM HAIDER Feb 9 '17 at 13:18
  • simple add a function payTestFunds() payable{ } was not enough then i made my constructor also payable. Now in my contract account i have 5 ether now i pay the bill but still same show the old value...not becoming 0 after paying the rent... – TAMIM HAIDER Feb 9 '17 at 14:56
  • edited my answer with pictures. I think this contract might be too busy to find firm footing. – Rob Hitchens - B9lab Feb 9 '17 at 15:20
  • strange thing...i have also tried similar....but not working... – TAMIM HAIDER Feb 9 '17 at 15:40
  • One thing that jumped out during testing was the inconsistent use of addresses passed in and msg.sender. I had to be careful that the addresses I passed to functions would match msg.sender in setCarRent() because the code works that way. – Rob Hitchens - B9lab Feb 9 '17 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.