2

Ia m newbie to smart contract world. Not able to execute smal smart contract written in solidity within Ethereum remix dev environment. I am simply using get set to return name, but while I supply name input no output is getting returned. Below is code.

Environment is: Javascript VM

pragma solidity ^0.4.0;

contract myHWSC
{
    string private name;
    uint private age;

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

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

}
Aniket
  • 3,545
  • 2
  • 20
  • 42
Munish
  • 43
  • 4
  • Paste the error you are getting in remix – Aniket Mar 31 '18 at 18:22
  • I am not getting any error. n right hand panel of Remix when I press "Create" under "Run" tab in Remix, I get below messages in left bottom panel
    creation of myHWSC pending... [vm] from:0xca3...a733c, to:myHWSC.(constructor), value:0 wei, data:0x606...60029, 0 logs, hash:0x72b...d8978 Details Debug transact to myHWSC.setName pending ...
    – Munish Mar 31 '18 at 23:00

1 Answers1

0

your code seems to be correct (Remix would display the output in the transaction details not in the right side panel).

you can alternatively use

function getName() constant returns (string)
{
    return name;
}
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
  • 1
    I would note that for functions, it's "view" and not "constant". Although for now, constant is an alias for it, it's deprecated and is planned to be dropped in version 0.5.0 of solidity – Elisha Drion Mar 31 '18 at 19:44
  • 1
    Thanks for the cmnt but does he use 0.5.0? – Badr Bellaj Mar 31 '18 at 20:17
  • No, but it's deprecated, and as I said, it's a, read well, note. – Elisha Drion Mar 31 '18 at 20:32
  • But how come in multiple tutorials by multiple people they all show testing in same way through the panel on right side? They input variable and output is displayed. I am confused. Is it because of insufficient gas that the contract is not getting created? – Munish Apr 01 '18 at 16:12
  • https://ethereum.stackexchange.com/questions/30004/nothing-returned-and-transact-pending – Badr Bellaj Apr 01 '18 at 16:16