Contracts, Functions, State Variables, Getters & Setters


#62

As for your first comment, about the create button, I still don’t understand the issue. Nobody has explained it to me. The button seems to have been renamed to deploy as I previously said and you doesn’t seem to have a problem deploying the contracts, am I right?

For your second issue, the problem is that you have an old compiler version. You can do 2 things to fix it, either use the “constant” modifier instead of “view”. Or select a newer compile version under the compile tab, one that is over 0.4.15 I believe.


#63

Correct. deploying is not an issue. using “constant” instead of “view” is solving the issue. although selecting a compiler even over 0.4.15 still doesnt allow me to use view. for simplicity, I will continue to use 0.4.0 and hope it doesnt require much else.

Thank you filip!


#64

I was actually wrong in my answer, it is version 16 and above. I tried now with v0.4.16+commit.d7661dd9, and that worked for me. Did you select the compiler version in the dropdown list in the compile tab?


#65

Yes, this is working well.


#66

whats the problem with my code I’m getting and error message
browser/new.sol:31:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
}pragma solidity ^0.4.0;

contract Person{
string name;
uint age;

function getName() view returns (string) {
    return name;
}

function getAge() view returns(uint){
    return age;
}
function setName(string _name){
    name = _name;
}

function setAge(uint _age){
    age = _age;
}

}


#67

You have an error at the beginning of the code. Before pragma you have a squirly bracket. Remove that and you will be fine.


#68

pragma solidity ^0.4.0;

contract Person{

string namePerson = "Inital Name";
int agePerson = 0;

function getName() view returns(string,int) {
    return (namePerson,agePerson);
}

function setOutput(string _nameOutput,int _ageOutput){
    namePerson=_nameOutput;
    agePerson=_ageOutput;
}

}


#69

Here is my contract

pragma solidity ^0.4.0;

contract Age{

uint Age = 1;
string Name = "Name";

function setName (string _Name) returns (string){
    Name = _Name;
}

function setAge (uint _Age) returns (uint){
    Age = _Age;
}

function getName (string)view returns (string){
    return (Name);
}

function getAge (uint) returns (uint){
    return (Age);
}

}

Couldn’t use “view” because of this error


#70

You have forgot to add a name to the argument to the getName function. It should look something like this:

function getName (string _name) view returns (string){
    return (Name);
}

#71

Actually it was like that but no difference error with view hasn’t disappeared


#72

I can see now that you have multiple errors in the code. As for the error with “view”: replace it with constant. It does the same thing but is compatible with the pragma version you are using.

But you shouldn’t have any arguments at all for the getter functions, that doesn’t make sense. You also need to rename Age to something else, since it can’t have the same name as the contract. You can use age, with a non-capital a.


#73

Ok I understand this, Thank You!


#74

I also had problems using “view”. I solved it by changing to version 0.4.25.

This is the code for the Name and Age contract…

pragma solidity ^0.4.25;

contract Person{

    string myName = "Fernando";
    uint myAge = 60;

    function getName() view returns (string){
        return myName;
   }   
    function setName(string _myName){
        myName = _myName;
    }

    function getAge() view returns (uint){
        return myAge;
    }   
    function setAge(uint _myAge){
        myAge = _myAge;
   }
}

#75

Great initiative. I hope to update the solidity chapter very soon with new videos. So that we can work with the latest version.


#76

pragma solidity ^0.4.0;

/// @title AllAboutMe
/// @notice Lesson 1 Response
/// @dev Xactant
contract AllAboutMe {
string myName = “NOT SET”;
uint myAge = 0;

function name() view public returns(string) {
    return myName;
}

function age() view public returns(uint) {
    return myAge;
}

function setName(string _name) {
    myName = _name;
}

function setAge(uint _age) {
    require(_age > 0);
    
    myAge = _age;
}

}


#77

Ran into the same issue - in Remix set the compiler version to at least 0.4.16 - will still compile with pragma solidity ^0.4.0;