3

Can any one provide end to end example "Hello, World" smart contract using browser solidity

4

Not as simple as it could be, but possibly more illustrative.

pragma solidity ^0.4.24;

contract HelloWorld {

    string saySomething;

    constructor() public  {
        saySomething = "Hello World!";
    }

    function speak() public constant returns(string itSays) {
        return saySomething;
    }

    function saySomethingElse(string newSaying) public  returns(bool success) {
        saySomething = newSaying;
        return true;
    }

}

It says "Hello World!", and we can change the message:

enter image description here

So when we summon it to speak, we get the new message:

enter image description here

Hope it helps.

  • pl send the steps to be followed to execute this , because whenever i put some message in saySomethingElse and clikc on speak , it only displays string it Says hello world instaed of message – NarraVasu Feb 21 '17 at 11:21
  • Clicking "speak" executes the speak() function. You need to click on the pink "saySomethingElse" to execute the saySomethingElse() function. – Richard Horrocks Feb 21 '17 at 11:49
1

Answer by Rob Hitchens - B9lab worked! I did face an error due to difference in version.In case you are using solidity version > 0.5.0, some changes that were required:

pragma solidity ^0.5.0;
contract HelloWorld {

    string saySomething;

    constructor() public  {
        saySomething = "Hello World!";
    }

    function speak() public view returns(string memory) {
        return saySomething;
    }

    function saySomethingElse(string memory newSaying) public  returns(bool success) {
        saySomething = newSaying;
        return true;
    }

}

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.