It is really easy to get up and running with Solidity smart contracts using Remix which is an online IDE for developing smart contracts in Solidity.

If you visit https://remix.ethereum.org/, you’ll see some sample code

Removing all the comments to make it less scary, you can see that the name of the contract is “Storage”, there is one variable called number of type uint256 which stands for an unsigned integer that is 256 bits long and then two functions. One to store the number and one to retrieve the number.

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.8.0;
contract Storage {
    uint256 number;
    function store(uint256 num) public {
        number = num;
    }
    function retrieve() public view returns (uint256){
        return number;
    }
}

And that is it really. Read this explanation of functions to demystify the key words such as public, view and returns and this smart contract should be easy to understand.

Below I’ve changed the code to store a string instead and changed the contract name to “helloWorld”

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.8.0;
contract helloWorld {
    string myString;
    function store(string memory str) public {
        myString = str;
    }
    function retrieve() public view returns (string memory){
        return myString;
    }
}

To run this, you will have to compile the contract first.

Then deploy the contract.

Now you can store a string and retrieve the string.

Leave a Reply

Your email address will not be published. Required fields are marked *