There is more than one way to create a 'hello world' smart contract in Ethereum. In this tutorial, I explain how to create a basic Ethereum smart contract.
In this tutorial, I explain how to create a basic 'hello world' smart contract in Ethereum. We will be using the Solidity programming language. And, we will be creating our smart contract in Remix the Ethereum IDE (integrated development environment).
To begin, go-to Remix. Ensure that the 'Solidity Compiler' and 'Deploy and Run Transaction' plugins are activated. If not, activate them in the Plugin Manager. (Ensure that you’ve selected 'Auto Compile' in the Solidity Compiler.)
Then, create a new file ending with '.sol' - that’s the abbreviation for the Solidity programming language. (You can enter whatever you wish for a filename.)
Enter the Solidity code below into Remix. That’s the 'hello world' smart contract in Ethereum. To help you understand the code, let me explain what the code is doing.
The file begins with an SPDX licence comment. These licences get commonly used in free and open or collaborative software, data, hardware, or documentation.
Then, the code starts with 'pragma' and the version of Solidity in use. The keyword 'pragma' is for the compiler to enable specific features (and run specific checks). And, the arrow next to the version tells the compiler which version and upwards to use.
Below, I declare something similar to a class in other programming languages. And open a pair of curly brackets. Within the code block, I create a public storage variable that will generate a Getter function.
Now, click on the 'Deploy and Run Transaction' plugin. Set the environment to 'Injected Web3'. MetaMask will pop up asking you to confirm the connection (I recommend that you set up a new MetaMask account with no funds, using one of the test networks.)
Your contract should now show under 'Contract'. Below that, click 'Deploy'. Now, MetaMask should pop up asking you to confirm the transaction: confirm it. Upon confirmation, the contract will get deployed (sent to get mined).
To interact with your smart contract, expand your contract under 'Deployed Contracts'. Now, click 'myString' - it should return 'hello world'.
That’s how you create a 'hello world' smart contract in Ethereum.