[Chainlink] How To Create a “Hello World” Smart Contract With Solidity

The journey to becoming an expert smart contract developer starts with a single step.

In this tutorial, you’ll learn how to build a “Hello World” smart contract with the smart contract development language Solidity. No prior knowledge is required—this tutorial is beginner-friendly. Even if you are not a developer, you can follow the step-by-step instructions to create your first smart contract using the Solidity language.

What Are Smart Contracts?

Smart contracts are computer programs published and executed in a blockchain environment. As they run on blockchains, they can be run without a central party or server.

Once a smart contract has been published, it is not possible to update or make any changes to its code due to the immutable nature of blockchains. However, the smart contract may have been programmed with functions to change data. This information can be recorded in one block and deleted in another, but the history remains and it is possible to audit.

Solidity Programing Language

Solidity is an object-oriented, high-level language for implementing smart contracts. It is a curly-bracket language, which means that the characters “{“ and “}” define statement blocks.

Solidity is influenced by C++, Python, and JavaScript, and is designed to run on the Ethereum Virtual Machine (EVM). It is statically typed and supports inheritance, libraries, and complex user-defined types, among other features.

Remix

Remix is an online web tool. It is an IDE (integrated development environment) used to write, compile, deploy, and debug Solidity code. Remix has an environment called JavaScriptVM, which is a blockchain simulator that runs in your browser. This tutorial will use it. Go to remix.ethereum.org to get started.

Create the Smart Contract

Click on the second icon on the left bar, “File Explorers”.

Click on the button “Create a new file”.

File name: HelloWord.sol

Files written in Solidity use the extension “.sol”.

Copy and paste this example:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract HelloWorld {
    function sayHelloWorld() public pure returns (string memory) {
        return "Hello World";
    }
}

Now let’s look at what’s in the smart contract.

// SPDX-License-Identifier

“//” means that this is a comment, not a code line.

The SPDX License List Specification is a list of common licenses used in free and open or collaborative software.

Solidity 0.6.8 introduces SPDX license identifiers so developers can specify the license the smart contract uses.

SPDX license identifiers should be added to the top of contract files, using the identifier “//”

// SPDX-License-Identifier: MIT

Pragma

This specifies the version of Solidity, using semantic versioning. Learn more here.

pragma solidity 0.8.13;

Contract HelloWorld

This defines a contract named “HelloWorld”.

A contract is a collection of functions and data (its state). 

Once deployed, a contract will exist at an address on the Ethereum blockchain. Learn more here

Function sayHelloWorld

This is a public function that returns the string “Hello World”. It is declared pure because it doesn’t read or modify the blockchain state.

Compile a Smart Contract

Locate in the left bar a button called “Solidity compiler”.

Click on the button “Compile HelloWorld.sol”.

It is useful to enable the auto-compile option.

Check the green sign at the button with the message compilation successful.

Deploy a Smart Contract

In the left side panel, go to the button “Deploy and run transactions”.

For now, we have only one smart contract, so it is automatically selected in the dropdown “Contracts.

Click on the button “Deploy”.

Interact With the Smart Contract

When a smart contract is deployed in Remix, we can see it in the left panel under “deploy and run transactions”:

  1. Scroll down the left side until you reach “Deployed Contracts”.
  2. Expand the “HelloWorld”.
  3. Click on the button “sayHelloWorld”.
  4. It will return the message recorded in the smart contract: “Hello World”.

Congratulations, you’ve created a “Hello World” smart contract!

Next Steps

Now that you’ve created your “Hello World” smart contract using the Solidity language, there are many possibilities available to you. You could deploy your contract to a testnet or even a mainnet, change the message, create a state variable to store the message, create a function to update the message, or save a message forever to a blockchain!

Learn more about Chainlink by visiting chain.link or reading the documentation at docs.chain.link. To discuss an integration, reach out to an expert.

The post How To Create a “Hello World” Smart Contract With Solidity appeared first on Chainlink Blog.

>> View on Chainlink

Join us on Telegram

Follow us on Twitter

Follow us on Facebook

You might also like

LATEST NEWS

LASTEST NEWS