Contracts, Functions, State Variables, Getters & Setters


#42

Hey man! share you code here so we can help? Cheers, kuki


#43

Here is my solution. It seems to work as expected.

pragma solidity ^0.4.0;

contract Person{
    string name;
    uint age;
    
    function getName() view returns (string){
        return name;
    }
    
    function setName(string _name){
        name = _name;
    
    }
    
    function getAge() view returns (uint){
        return age;    
    }
    
    function setAge(uint _age){
        age = _age;
    }
    
}

#44

// @Guactoshi : thank you for the hint… You made this code look way more simple than what I initially did. Here goes my correct answer :slight_smile:

pragma solidity ^0.4.0;

contract Person {

string name = "Juliana Banana";
uint age = 32;


function getAge () view returns (uint) {
    return age;
}

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

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

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

}


#45

Hello Everyone! Excited to be starting on the smart contract coding. Here is my code:

pragma solidity ^0.4.24;

contract Person{
    uint256 age = 0;
    string name = "";
    
    function getAge() view returns (uint256){
        return age;
    }
    function getName() view returns (string){
        return name;
    }
    function setAge(uint256 _age){
        age = _age;
    }
    function setName(string _name){
        name = _name;
    }
}

Shouldn’t be too different from everyone else’s, but do share if you have any thoughts!


#46

I have problem in remix with view. When I use view it give me error. If I write without view everything is fine. any thouts?


#47

pragma solidity ^0.4.0;

contract Person{
uint age = 0;
string name = “”;
function setName(string _name){
name = _name;
}
function getName()returns(string){
return name;
}
function setAge(uint _age){
age = _age;
}
function getAge()returns(uint){
return age;
}
}


#48

Hey guys! My first Solidity contract shared with the world :slight_smile: :

pragma solidity ^0.4.0;

contract YourDetails {

string name;
uint age;

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

function showAge() view returns (uint) {
    return age;
}

function enterName(string yourName) {
    name = yourName;
}

function enterAge(uint yourAge) {
    age = yourAge;
}
}

#49

Can you share the code and the error?


#50

pragma solidity ^0.4.0;

contract Person{
uint age = 0;
string name = “”;
function setName(string _name) public {
name = _name;
}
function getName()view public returns(string){
return name;
}
function setAge(uint _age) public{
age = _age;
}
function getAge()view public returns(uint){
return age;
}
}

for uint everything is ok. for function with string Ihave problem
when code is like above this error I get

browser/Untitled.sol:6:18: TypeError: Data location must be “memory” for parameter in function, but none was given.
function setName(string _name) public {

when I leave public and write without I get this error

browser/Untitled.sol:6:1: SyntaxError: No visibility specified. Did you intend to add “public”?
function setName(string _name) {
^ (Relevant source part starts here and spans across multiple lines).


#51

sorry to bother you
Looks like everithing is ok i chrome.
I use brave browser and forget to check in chrome


#52

Put String type in Double Quotes


#53

Hi there, I am stuck on the first contract example, I have typed the example syntex correctly but I cant see the button CREATE on Remix after clicking RUN, Could somebody help please?
Uploaded is the Screenshot of the Remix.

Regards
Michael


#54

pragma solidity ^0.4.0;

contract assingmentOne {

string name;
int age;

function getName () view returns (string) {

 return name; 

}

function getAge () view returns (int) {

 return age; 

}

function setName (string _name) {

  name = _name;

}
function setAge (int _age) {

age = _age;

}
}


#55

Click the deploy button, it does the same thing.


#56

Hello,

At the end of the video, Filip says “Remember to do all the exercises and quizzes after this”. Is there any exercise/quiz? I can’t find any…

Thanks!


#57

No, I say that in way to many videos. It’s a mistake on my part. If there is a quiz, do it. Otherwise don’t worry.


#58

Hi Filip,

I am still having problem with Create and Deploy Buttons in Remix IDE, I have also tried it in Firefox browser but still same problem.
Is there any solution to this problem because I stuck and can not move to the next step without practice coding. Could you please show any other compiler I can use


#59

What’s the problem? I would be happy to help but I need to know more.


#60

I am having the same issue. it looks like there has been some kind of change. the contracts now get created immediately without use of the button ‘create’ and the example getter syntax is not working and it immediately removes the contract from the compiled contract list, making it unable to deploy it:

the error keeps pointing at “view”. Once this is removed the function is back to normal and the contract, along with the deploy button comes back. so how do we write getters now?


#61

pragma solidity ^0.4.0;

contract Person{

string nameOutput = "";
uint ageOutput;


// getter function for name
function getName() view returns (string) {
    return nameOutput;
}

    // getter function for age 
  function getAge() view returns (uint) {
    return ageOutput;
}      


// setter function for name
function setName(string _name) {
    nameOutput = _name;
}

// setter function for age
function setAge(uint _age) {
    ageOutput = _age;
}    

}