Original title: " Solidity minimalist entry: 1. HelloWeb3 (three lines of code) "
Original source: 0xAA
I am re-learning solidity recently, to consolidate the details, and also write a "Solidity minimalist introduction" for beginners to use (programmers can find another Tutorials), 1-3 lectures are updated every week.
All codes are open source: github: github.com/AmazingAng/WTFSolidity
Solidity is the language of Ethereum Virtual Machine (EVM) smart contracts. At the same time, I also think that solidity is a necessary skill for playing on-chain projects: most blockchain projects are open source, and if you can understand the code, it can help you avoid many money-losing projects.
Solidity has two characteristics:
- Object-based: After learning, it can help you Make money and find someone.
- Advanced: Does not know solidity, looks very low in the currency circle.
In this tutorial, I will use remix to run the solidity contract . remix is the smart contract development IDE officially recommended by Ethereum. It is suitable for novices. It can quickly deploy and test smart contracts in the browser. You don't need to install any programs locally.
URL: remix.ethereum.org
p>
Enter remix, we can see that there are three buttons on the leftmost menu, corresponding to file (where to write code), compile (run code), Deploy (deploy to chain). We click the Create New File button to create a blank solidity contract.

remix panel
Very simple, only 1 line of comment + 3 lines of code:

We disassemble and analyze to learn the structure of the solidity code source file:
1 . The first line is a comment, and I will write about the software license (license) used by this code, here is the MIT license. If the permission is not written, a warning will be issued when compiling, but the program can run. Solidity comments start with "//", followed by the content of the comment (will not be run by the program).

2. The second line declares the solidity version used by the source file, because the syntax of different versions is different.

This line of code means that the source file will not be allowed to compile with a compiler version lower than 0.8.4.
3. Lines 3-4 are the contract part, line 3 creates the contract and declares the contract The name is HelloWeb3. Line 4 is the content of the contract. We declare a string (string) variable _string and assign it the value "Hello Web3!".

We will introduce the variables in solidity in more detail later.
On the code editing page, press ctrl+S Compile the code, very convenient.
After compiling, click the "Deploy" button on the left menu to enter the deployment page.

By default, remix will use the JS virtual machine to simulate the Ethereum chain and run smart contracts, similar to running a test chain in a browser. And remix will allocate several test accounts to you, each with 100 ETH (test token), which can be used vigorously. You click Deploy (yellow button) to deploy the contract we wrote.

After successful deployment, you will see a contract named HELLOWEB3 below, click _string, and you will see "Hello Web3!" written in our code.
In the first lecture, we briefly introduced solidity and remix tools, and completed Created the first solidity program - HelloWeb3. Next we will introduce the various variable types of solidity.
Chinese solidity material recommendation:
Solidity Chinese document (Chinese translation of official document): https://solidity-cn.readthedocs. io/zh/develop/introduction-to-smart-contracts.html
Cui Mian master solidity tutorial (web3 technology teaching blogger, I learned from his video Many): https://space.bilibili.com/286084162
Original link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia