solidity is the most popular language for writing smart contract for the Ethereum blockchain.today 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 data types in solidity are statically typed
So declaring a variable ,the name of the variable must be preceded by the variable type
E.g
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
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 helloWorld;
Constructor () public {
helloWorld = "hello world";
}
}
`
Happy ccodingππ
Top comments (0)