0

I am using truffle with angular to write DAPP. I have a factory contract which will deploy an other contract named rental through a function called newContract. here is my factory contract

pragma solidity ^0.4.8;
import './RentalContract.sol';


contract ContractFactory {
  address[] public contracts;

  function ContractFactory() {
  }
  function getContractCount() public constant returns(unit contractCount) {
    return contracts.length;
  }

  function newContract(unit _rent, unit _security_deposit, string _house, address _owner, address _tenant)
  public returns(address newContract) {
    Rental c = new Rental(_rent, _security_deposit, _house, _owner, _tenant);
    contracts.push(c);
    return c;
  }
}

and my Rental contract looks like following.

pragma solidity ^0.4.8;

contract Rental {
    struct PaidRent {
        unit id;
        unit value;
    }
    PaidRent[] public paidrents;

    unit public createdTimestamp;
    unit public rent;
    unit public security_deposit;
    string public house;
    address public owner;
    address public tenant;

    enum state {Created, Started, Terminated}
    State public state;
    function Rental(unit _rent, unit _security_deposit, string _house, address _owner, address _tenant) {
        createdTimestamp = block.timestamp;
        rent = _rent;
        security_deposit = _security_deposit;
        house = _house;
        owner = _owner;
        tenant = _tenant;
    }
    modifier require(bool _condition) {
        if(!_condition) throw;
        _;
    }
    modifier LandlordOnly() {
        if(msg.sender != landlord) throw;
        _;
    }
    modifier TenantOnly() {
        if(msg.sender != tenant) throw;
        _;
    }
    modifier inState(State _state){
        if(_state != state) throw;
        _;
    }

    function getPaidRents() internal returns (PaidRent[]) {
        return paidrents;
    }

    function getHouse() constant returns (String) {
        return house;
    }
    function getLandlord() constant returns (address) {
        return landlord;
    }
    function getTenant() constant returns (address) {
        return tenant;
    }
    function getRent() constant returns (unit) {
        return rent;
    }
    function getDeposit() constant returns (unit) {
        return security_deposit;
    }
    function getContractCreated() constant returns (unit) {
        return createdTimestamp;
    }
    function getContractAddress() constant returns (address) {
        return this;
    }
    function getState() returns (State) {
        return state;
    }
    function CollectEth() payable  {}

    function payRent() TenantOnly inState(State.started) require(msg.value == rent) {
        landlord.transfer(msg.value);
        paidrents.push(PaidRent({
            id : paidrents.length + 1,
            value : msg.value
        }));
    }

    function terminateContract(address deposit_to) inState(State.started) require(this.balance == security_deposit) {
        deposit_to.transfer(security_deposit);
        state = State.Terminated;
    }



}

but when i run truffle compile i am having following error. enter image description here

any idea what is wrong here?

  • Change unit -> uint. – ivicaa Mar 20 '18 at 20:11
1

uint not unit.

It might be helpful to play around in Remix just to catch errors like that before moving on to Truffle. Set the compiler version to the same solc you see when do a truffle version.

Hope it helps.

  • thanks a lot man, my truffle version is Truffle v4.0.6 (core: 4.0.6) and solidity version is Solidity v0.4.19 (solc-js). do i need to change solc to 4.0.6? – Shoaib Iqbal Mar 20 '18 at 20:24

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.