[Ethereum] Solidity compile Expected token Comma got ‘Identifier’

ethereum-classicsolidity

I'm trying to compile a contract in the solidity browser compiler and get this error:

Expected token Comma got 'Identifier'
person.setRent(uint256 _rent);

What is the token Comma in this case?

My contract:

contract Landlord is user {
    string public landlordName;
    string public physicalAddress;
    function Landlord(
        string _name,
        string _physicalAddress){

        landlordName = _name;
        physicalAddress = _physicalAddress;
    }

    function setRent(uint256 _rent, address _tenantAddress){
        Tenant person = Tenant(_tenantAddress);
        person.setRent(uint256 _rent);

    }

Best Answer

Tl;dr: Get rid of the uint256.


The changes I had to make to get your code working are to:

  • Define a contract User as your contract code refers to user in contract Landlord is user. I renamed user to User to keep with the case convention;
  • Define a contract Tenant as your contract code refers to the statement Tenant person = Tenant(_tenantAddress);;
  • Define a method setRent(uint256 _rent) in the contract Tenant as your contract code calls setRent(...) in the statement person.setRent(uint256 _rent);; and
  • Remove the uint256 from your call to setRent(...).

Here's the code I modified to get your code to compile correctly:

pragma solidity ^0.4.0;

contract User {
}

contract Tenant {
    address tenant;
    uint256 rent;

    function Tenant(address _tenant) {
        tenant = _tenant;
    }

    function setRent(uint256 _rent) {
        rent = _rent;
    }
}

contract Landlord is User {
    string public landlordName;
    string public physicalAddress;

    function Landlord(
      string _name,
      string _physicalAddress) {
        landlordName = _name;
        physicalAddress = _physicalAddress;
    }

    function setRent(uint256 _rent, address _tenantAddress){
        Tenant person = Tenant(_tenantAddress);
        person.setRent(_rent);
    }
}    

Here's a screenshot of your modified code compiling in the Solidity realtime compiler and runtime:

enter image description here

Related Topic