DEV Community

Cover image for Hello world in Solidity
Hillary Chibuko
Hillary Chibuko

Posted on


Hello world in Solidity

solidity is the most popular language for writing smart contract for the Ethereum I'm going to be showing you how to print "hello word" in solidity.
Firstly the solidity smart contract code starts with a pragma declaration which specifies the version of the compiler to compile our smart contract code

pragma solidity ^0.8.2

The caret symbol before the version number tells the compiler that any compiler version above 0.8.2 can be used to compile the smart contract...
A compiler of 0.9.0 would throw an error same as 0.7...n

After the Pragma declaration then we move to declaring the contract block

contract HelloWorld {}

This is the block that contains all the code for our smart contract,anything outside this block should be either another smart contract definition or Pragma declaration.

Then we move to declaring a string variable to store our text.
Also it is to be noted that solidity is a statically typed language

So declaring a variable ,the name of the variable must be preceded by the variable type
string public helloWorld;
Statement in Solidity should end with a semicolon.

and the public declaration before the variable name simply means that the variable can be accessed outside the smart contract..
Meaning any smart contract that inherits from this contract can call this variable and it also can be called from outside the smart contact

Now I move to declaring the constructor function that assigns value to the variable

constructor() public {
helloWorld = "hello world";

Now it's time to put the pieces together

`Pragma solidity ^0.8.2;
contract HelloWorld {
string public

   Constructor () public {

       helloWorld = "hello  
Enter fullscreen mode Exit fullscreen mode


Happy coding🎉🎉

Top comments (0)