0

I have written a smart contract with the Getter and Setter functions but it is not showing any output in IDE-Remix. My code is '''

pragma solidity ^0.4.21;

contract GetandSet{

    string name;
    uint age;

    function GetandSet() public {



    }

    function set(string newName, uint newAge) public {

        name = newName;
        age = newAge;
    } 


    function get() public view returns (string, uint) {

        return (name,age);
    }


}

'''

  • How are you testing it? It works just fine here. Just choose the right compilier version, deploy it to JavaScript VM, issue a set with some values and issue a get – Lauri Peltonen Apr 29 at 13:30
  • I am compiling it through Remix -IDE (browser-based) and using the compiler version 0.4.21. – Khizar Hameed Apr 29 at 13:32
0

Your code works just fine. I guess you have problems using Remix.

So:

1) Choose the right compiler (0.4.21)

2) Deploy the contract

3) Call set with some values

4) Call get and you should see the set values

Attached is a screenshot of the setup I tested with. As you can see, the get function gives the correct results.

Instructions

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.