> For the complete documentation index, see [llms.txt](https://docs-legacy.kleros.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-legacy.kleros.io/developer/arbitration-by-example/rental.sol.md).

# Rental.sol

```solidity
pragma solidity ^0.4.15;
import "./TwoPartyArbitrable.sol";

/** @title Rental
 *  This is a a contract for rental agreement.
 *  This can be used to rent objects or properties.
 *  Party A is the renter. Party B is the owner.
 *  Party A put a deposit. If everything goes well, it will be given back.
 *  Otherwize parties can claim an amount of damages. If they disagree, the arbitrator will have to solve this dispute.
 */
contract Rental is TwoPartyArbitrable {
    string constant RULING_OPTIONS = "Rule for party A (renter);Rule for Party B (owner)";
    uint8 constant AMOUNT_OF_CHOICES = 2; // The number of ruling options available.

    uint public amount; // Amount sent by party A.
    uint public damagesClaimedByPartyA; // The amount party A agrees to pay to compensate damages.
    uint public damagesClaimedByPartyB; // The amount party B claims to compensate damages.

    /** @dev Constructor. Choose the arbitrator. Should be called by party A (the payer).
     *  @param _arbitrator The arbitrator of the contract.
     *  @param _timeout Time after which a party automatically loose a dispute.
     *  @param _partyB The owner.
     *  @param _arbitratorExtraData Extra data for the arbitrator.
     *  @param _metaEvidence Link to meta-evidence JSON.
     */
    constructor(
        Arbitrator _arbitrator, 
        uint _timeout, 
        address _partyB, 
        bytes _arbitratorExtraData, 
        string _metaEvidence
    ) 
        public 
        TwoPartyArbitrable(_arbitrator,_timeout,_partyB,AMOUNT_OF_CHOICES,_arbitratorExtraData, _metaEvidence) 
        payable 
    {
        amount += msg.value;
    }

    /** @dev Claim an amount of damages.
     *  Must be called before the dispute is created.
     *  If the amount agreed is the same for both, pay it.
     *  @param _damages The amount asked or agreed to be paid.
     */
    function claimDamages(uint _damages) public onlyParty {
        // Make sure that parties can't change when a dispute already started.
        require(status < Status.DisputeCreated, "The dispute has already been created.");
        // Needed to avoid claiming 0 first and triggering an agreement. Use forfeitDeposit and unlockDeposit for the cases where 0 is claimed.
        require(_damages != 0, "There must be damages.");
        require(_damages <= amount, "Cannot claim more than balance."); // Make sure not to claim more than the contract has.

        if (msg.sender == partyA)
            damagesClaimedByPartyA = _damages;
        else
            damagesClaimedByPartyB = _damages;

        if (damagesClaimedByPartyA==damagesClaimedByPartyB) { // If there is an agreement.
            partyA.send((amount - damagesClaimedByPartyB) + partyAFee);
            partyB.send(damagesClaimedByPartyB + partyBFee);
            damagesClaimedByPartyA = 0;
            damagesClaimedByPartyB = 0;
            partyAFee = 0;
            partyBFee = 0;
            amount = 0;
            status = Status.Resolved;
        }
    }




    /** @dev Forfeit the deposit to party B.
     *  To be called if the good has been completely broken or that the property damages exceed the deposit.
     */
    function forfeitDeposit() public onlyPartyA {
        partyB.transfer(amount);
        amount = 0;
    }

    /** @dev Unlock party A deposit. To be called if the good or property has been returned without damages.
     */
    function unlockDeposit() public onlyPartyB {
        partyA.transfer(amount);
        amount = 0;
    }

    /** @dev Execute a ruling of a dispute. It reimburse the fee to the winning party.
     *  This need to be extended by contract inheriting from it.
     *  @param _disputeID ID of the dispute in the Arbitrator contract.
     *  @param _ruling Ruling given by the arbitrator. 1 : Rule for party A (renter). 2 : Rule for Party B (owner).
     */
    function executeRuling(uint _disputeID, uint _ruling) internal {
        super.executeRuling(_disputeID,_ruling);
        if (_ruling == PARTY_A_WINS) {
            partyA.send(amount - damagesClaimedByPartyA);
            partyB.send(damagesClaimedByPartyA);
        }
        else if (_ruling == PARTY_B_WINS) {
            partyA.send(amount - damagesClaimedByPartyB);
            partyB.send(damagesClaimedByPartyB);
        }

        amount = 0;
        damagesClaimedByPartyA = 0;
        damagesClaimedByPartyB = 0;
    }

}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-legacy.kleros.io/developer/arbitration-by-example/rental.sol.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
