Hello World In Solidity
Table of contents
Solidity is an object-oriented, high-level programming language used to implement smart contracts. Because it is a curly-bracket language, the characters "{" and "}" define statement blocks.
Here is an example of how to write a hello world smart contract using solidity . Here I am using Remix IDE to write smart contracts and deploy in to Etherium test network . First go this link and open Remix IDE . Remix is a web-based application. It is an integrated development environment (IDE) for writing, compiling, deploying, and debugging Solidity code. Remix has a JavaScriptVM environment, which is a blockchain simulator that runs in your browser.
In File section under contracts folder create file called HelloWorld.sol
Then write this code inside that file
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
contract HelloWorld {
function helloWorld() public pure returns(string memory){
return "Hello World";
}
}
// SPDX-License-Identifier
"//" means that this is a comments , that how in solidity we write comments The SPDX License List Specification is a list of common licenses used in free and open or collaborative software.
pragma solidity ^0.8.7;
This specifies the version of Solidity This public function returns the string "Hello World" . Here we used pure because it does not read or modify the blockchain state.
The next step is to compile this HelloWorld Contract. To do that, navigate to Solidity Compiler on left side menu .
Click the "Compile HelloWorld.sol" green button. Make sure you choose the correct compiler version.
Next, after compiling the smart contract, click the Deploy & Run transaction tab in the left side navbar.
Before move on next step you should install chrome extension called MetaMask
After installing Metamask, open it . First you have to setup the Meta Mask wallet. It's a very easy step . After successfully creating the wallet, open it , and you should switch on test networks also . You can do it in advance by setting options. Here i am using the Goerli Test network . Before you can deploy smart contracts, you need to have ETC on your Goerli Test network . to get free GOerli ETC, go this website and put your wallet address .
wait few minutes it will come into your wallet. Using this ETC, we can launch our Hello World smart contract.
Okay, let's deploy our contract.
Here, the environment chose Inject Provider - Metamask After click Deploy button.
Then it will open Metamask App and click continue button . Wait a few minutes until deployment is complete. After a successful deployment, you will like this under Deployed Contracts
Now click the helloWorld button. It will return the Hello World string. That's it. Thank you
Subscribe to my newsletter
Read articles from Malinda Jayawardana directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by