4

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);

    }
1

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

  • 5
    You might want to put a "Tl;dr: Get rid of the uint256." at the top – Tjaden Hess Oct 2 '16 at 1:51
2

Note that a bracket is missed in the end }, please provide the whole code. note that the setRent has 2 parameters while you are calling it with just one parameter, you are overloading this function so you need to define it in your previous code.

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.